How can I fix a loose door frame?
The first thing I'd do is one-by-one, remove the screws in the hinges and replace them with 3" #8 screws.  This should definitely secure the frame to the stud, and the door to the frame.  It might also fix your lock alignment problem, but if not, usually all that is needed is to move the strike up/down or in/out a bit.  Take the strike off completely - does the door latch correctly now? If so, you just need to position the strike correctly.  If it does not, that means the original hole is not aligned correctly and you will need to either enlarge it, or if it is way off, drill another hole and re-install the strike.