Just to confirm, on the 40D, Av will select the shutter speed for ambient light exposure, according to the f/number and ISO. The flash moderates power to match f/number and ISO. That's the default setting - there is also a custom function which locks the shutter speed at 1/250sec when you select Av, if you want.
On P, it works the same way except the shutter speed will only drop to match the ambient as low as 1/60sec. The camera then decides that it is preferable to let the background go dark, rather than risk subject blur in the background.
Couple of things: Av is usually the favourite mode and it's a doddle to change the image brightness, if the camera's auto result doesn't suit. To lighten/darken the flash, adjust the +/- compensation on the gun (moderates flash power); to lighten/darken the background, adjust the +/- compensation on the camera (moderates shutter speed). With a bit of practise, it takes seconds to get any kind of brightness ratio you want. Sorted
If the subject is off-centre, this can fool the flash which then tries to expose for the background, resulting in over exposure of the main foreground subject. So point the camera at the subject, press the FEL button (flash exposure lock) which will fire the pre-flash and set the exposure correctly. Then re-compose and shoot - flash fires at the correct locked setting (see handbook).
When using flash outdoors for fill-in when it's bright, the camera will sometimes want to run higher than the max x-sync of 1/250sec. Just switch the flash to High Speed Sync (HSS) and it increases the light output duration to cover the full shutter cycle. You lose a bit of range this way, but that's not a problem if the subject is reasonably close. In fact you can just leave the flash switched permanently to HSS and it will automatically engage when the shutter speed goes over 1/250sec, and disengage when it drops back again.