Can rigid foam board have an air space between it and rim joist?
Spray foam would not be either an ideal or recommended procedure to cover up all the wires where they exit from the main power panel. The first moment when some electrical problem needs troubleshooting, you need to add a new circuit or an existing wire needs moving you will be cussing that you ever thought of spraying in foam in this area.