When you are working on getting trim to fit tightly around a window, be sure to perfect the mitre corners first, and then cut the square length last. That way, if you have to adjust the mitre, you still have enough length to the wood to fit the other end.
One way to assure a perfect fit is to rough cut the mitre first, about one saw's width too long. Then place both pieces into a simple little square jig and then cut down the middle of the cut. You will be cutting both sides by half a saw's kerf width. You may need to repeat the cut, but when you finally cut a little on both sides, you will have a perfect fit, even if you haven't cut at exactly 45 degrees. This is especially useful when one piece is not the same width as the other and you are not even cutting at 45 degrees but cutting from the inside corner to the outside corner.
For a more complete overview including a mitre saw mitre/bevel angle chart, check out Cutting Crown Molding With A Mitre Saw.