You might need to cut some wooden fillets for the larger gaps and then use epoxy resin and nails or screws to hold them in place whilst the adhesive sets. You can then use your caulk/MS polymer to fill the small remaining gap.
You don't seem to have anything for expanding foam to cling to. If you can access the loft and wedge something in to the edge, the foam can bond to that.
If you need to find a tradesperson to get your job done, please try our local search below,
or if you are doing it yourself you can find suppliers local to you.
Select the supplier or trade you require, enter your location to begin your search.
Please select a service and enter a location to continue...
Are you a trade or supplier? You can create your listing free at DIYnot Local