Firstly, P doesn't always select the best exposure...and how could it? The camera doesn't know what you, the photographer, is trying to accomplish.
Aperture and shutter priority do give you more control, the the exposure is still based on the camera's meter reading, so you get the same exposure as you would in P mode.
The camera's meter is designed to give you 'proper' exposure for a scene that is 18% (middle) grey. This is great if your scene is actually mid-toned (or at least the part of the scene that your meter is reading) but if your scene or your subject is not the same tone as middle grey, then the exposure the camera gives you, may not be what you want to use.
In this case, you can use EC (exposure compensation) to off-set the camera's meter reading. For example, if you set it to +1 stop, your exposure will be one stop brighter than the camera's metered values. Sometimes you will want to be over, sometimes under, it depends on the subject/scene and what you, the photographer, wants to do.
As for M mode, this allows us to set our exposure without the camera interfering with it. You can still use the camera's meter to find your settings, but they won't change if the meter picks up something that would mess with the auto modes.
We might also use M mode when shooting with external strobe lights because the camera can't meter for them, so using the auto modes wouldn't be much help.
The fact of the matter is that it doens't really matte what mode you are in...as long as you get the exposure that you want. A shot taken with settings of; F8, 1/125 and ISO 100...will look the same, no matter what exposure mode you are in.