Measure the width of the opening along the top, from corner to corner, at the edge of the casing.
Transfer the measurement to a piece of window trim, making one pencil mark 3 or 4 inches in from the end and measuring off that mark by the measured span, then making a second mark. Both marks should be on the bottom edge of the piece.
Set the trim on the miter saw, face up, with the bottom edge against the back fence of the saw. Position the trim so one mark is under the blade. Turn the blade to point 45 degrees outward, toward the closest end of the trim. Make the cut.
Move the trim so the second mark is under the blade. Swivel the blade to point 45 degrees toward the closest end, which will be in the opposite direction as before. Cut it.
Hold the trim to the top of the opening, so the two mitered ends span out and up from the upper corners. Secure it with your trim nailer, shooting the nails every foot or so along the upper and lower edges.
Measure and cut trim for the remaining three sides of the opening. Install the pieces with the ends pressed tightly at the miters, to form the corners of the frame.
Caulk the lines where the trim meets the wall and the casing.