How can I insulate behind pipes that are close to a foundation wall?
Cut the foam into manageable pieces and slide into place.  Use cans of spray foam insulation to fill the cracks in the sheets of foam caused by cutting.

Or spray foam the entire cavity and forget the rigid foam.