Remove any old insulation and rotted wood framing and replace it. You should have the area down to the wood frame. Put weather protection in place. Check the size of the opening and allow for the thickness of flashing. Make sure that the window is plumb by measuring from the left upper corner to the right lower corner. Do the same from the upper right to the lower left. These two diagonals need to be the same or within 1/8 inch.
Slice the house wrap in the middle, fold it in and staple it. At the top, you'll also need to create a flap of house wrap the width of the flashing and staple it into place. Put flashing on the lower sill and staple the corners down.
Slide the window in and use wood shims at the sides, bottom and top to make sure you have it properly centered. Once you're comfortable that it's centered, tack down the corners as a temporary measure to keep it centered. Use sealant on the flange overlaps. Overlap the bottom ones with those on the top.
Move to the interior so you can center and shim the sides, top and bottom. Again, you'll need to check the diagonal to make sure that the window is plumb. Once you're comfortable, move back to the outside and permanently fasten the window down every 6 to 8 inches. If you have a jointed model with brackets and plates, make sure you fasten them.
Put flashing at the sides. You'll need to overlap the sill flashing when you do this. Put 1/4-inch-wide sealant at the top and then fold down the house wrap and tape into place. Cut off the shims so that they're flush and don't stick out. Move back to the inside of the house.
Cut off the shims so that they're flush and don't stick out. Move back to the inside of the house to seal the sides with low expanding foam or a backer rod and sealant.
Return to the outside and insert a backer rod all the way around the window frame. A putty knife works well for this. Once it's in, put a sealant all the way around the window.