I see two choices for the large gaps:
- Continue to piece-meal it with whatever scraps of lumber/plywood/OSB you may have laying around.
- Remove the random bits stuck in there and cover it with a single sheet of plywood/OSB. This might involve adding some 2x4 or 2x6 blocking to attach the sheet goods to. Again, whatever you've got on hand, or whatever's cheap at the big-box store today. This isn't structural, you're just looking to stop air flow.
If you want/need insulation here, feel free to add fiberglass, rockwool, foam board or whatever other insulation is necessary to whatever R-value you need, then cover it up.
Once the big gaps are covered up, spray foam around all the corners, edges, and penetrations. If there are places where you couldn't get a tight fit and the gap is still a bit big for the spray foam, push backer rod in first and spray foam over that.
Use fire-block rated foam if there's space above this, such as additional living space or an attic, or if there are appliances nearby that could cause a fire (such as HVAC equipment or a dryer).