It's pretty simple.
You have your pre-scaler, which you said you set to MCK/8
By default the PWM cycle starts off, at 0 the clock starts running and for every 8 MCK ticks the PWM timer will increment by 1, when it reaches duty cycle it will turn off, when it reaches period it will turn on and reset. There are bits to control the exact functioning of the PWM in the datasheet, there are different modes that being the simplest.
Say you have MCK of 20Mhz, thats 50ns per clock tick. You're using a prescaler of 8 so that's 400ns, 40khz has a time constant of 25usec \ 400ns = a period of 62.5 cycles. Can't do that obviously so round up to 63. That's only 7 bits for the PWM though not very good.
No prescaler, Ie running the PWM clock directly off of MCK gives you straight 50ns per 1 value of period so 25u \ 50 = 500 dead even for 40khz, which will give you a duty cycle range of 1-500 or just shy of 9 bits.
If you want 8 bits even so you don't have to do any data scaling from .wav files work the other way and you get a period of 256 * 50ns = 78125hz which seems reasonable to me. Not sure what it's gonna sound like, but make sure you put a low pass filter with a cutoff frequency of about 20khz in there and modulate the duty cycle with and audio tone you'll get something out.