Measure across the width of the window opening while the existing window is still in, getting the reading from inside the tracks where there sashes sit, sliding the sashes up or down as needed. Do the same for the height of the opening.
Order the replacement window unit using those measurements. Leave the old windows in until the new ones arrive.
Pry off the trim border from around the inner edge of the window opening to get the old window sashes out. Don't break the trim as you remove it. Set it aside.
Set the new window unit in the opening, bottom end first. Push in the top until it's stopped by the trim around the outside of the opening.
Put a level on the unit and slide wood shims in around the edges of it until it's level and square.
Shoot long screws outward through the holes in the sides of the window unit, into the surrounding frame, to secure it.
Tuck fiberglass insulation into the spaces around the perimeter of the window.
Use your trim nailer reinstall the trim around the inner border of the new window unit, hiding the spaces and trapping the new unit in place. Caulk around the trim and the window unit.