Use a small chisel knife to scrape away any rotting or damaged sections of the wall around the window frame.
Clean the area around the window with a damp sponge and mild detergent to remove any dirt, mold or debris.
Roll a piece of repair putty in your hands until it is pliable and then apply it to any damage around the window to fill it in. Smooth the putty out with a trowel once it is in the wall and let it dry. It hardens and fills in gaps or dents that contribute to the frame coming loose.
Smooth out the putty using fine sandpaper so that it is even with the wall. Prime and repaint the wall if you need to before reattaching the frame.
Place the screws into the holes and drill the frame back into the wall using a power drill. Use slightly wider screws than before to help support the frame in the wall.