Measure the dimensions of the opening while the old unit is still in, from the points where the edges of the unit butt to the sides of the opening. Order a new window unit with these measurements.
Remove the trim from around the interior edge of the opening using a hammer and pry bar. Don't break the trim as you take it out. Set it aside. There should be exposed space around the perimeter of the unit where the trim was.
Run a reciprocating saw inside the space around the perimeter of the window, cutting through the screws that hold it in place. Pull the entire unit out of the opening. Use a hammer to pound down any remaining screw pieces jutting from the sides of the opening.
Stand the base of the replacement window unit on the bottom span of the opening. Push the top of the unit up and into the opening until it butts against border of trim around the exterior side.
Square the window by setting a level alongside it and shimming around the sides and bottom until it's level and plumb at all points.
Shoot screws outward through the screw holes in the sides of the unit and into the surrounding frame.
Spray insulation foam into the spaces around the perimeter of the window.
Re-install the trim that you took off earlier, using a trim nailer. The trim should cover the spaces around the edges of the windows. Caulk around the edges.