How to fix a (bathroom) door that keeps swinging closed?
You described two problems. One, the door not latching closed easily; two, the door swinging closed by itself. These may or may not be related. ...

1) If the latch and latch hole in the frame do not line up horizontally, then you may need to adjust the position of the latch hole and/or file the hole in the metal latch guide to enlarge it slightly. A Dremmel or similar tool is very handy for this repair. 

2) If the latch and latch hole in the frame do not line up vertically, then the two problems can likely be fixed with shims behind the middle and the upper or lower hinges, depending on whether the door latch needs to move up or down.


2a) If you shim to where the latch works but the door is still moving by itself you can put a hammer to the hinge pins to give them a slight bend - they can handle a pretty good blow and the bend is barely noticeable. This will put a small amount of resistance in the hinges to keep the door open.