P.F.
The local Pet stores carry a product for just this problem, you spray it on, quite a lot, and it removes the odors. It works. You have to use it every time though. I had an old dog that lost control and I used to put the stuff into the steam carpet cleaner and it really got deep down.
I would also suggest getting the dog a physical to see if there might be an underlying physical ailment causing this. If you're talking about a puppy, well then you need to do some intense training, asap....good luck