Maintaining head to wind
Don''t know what kind of boat you have but.. Why not leave the motor running to keep the boat headed into the wind until you raise the sail? Or maybe you are being pulled by another boat, which you could remain with the boat, head to wind while raising the sail.
When I am reefing my main, I leave the jib up which maitains headway, release the pressure on the main by sheeting out, drop the main to the reefing points, secure it and then sheet back in.
I sailed dinghy''s a long time ago but don''t know the answer to the sail away during recovery from capsizing. I remember being in the boat, using the centerboard as a step before the sail was up in the wind, and the boat always had a tendency to round up as you raised it not veer off.