It sounds like secondary encopresis.
My five year old has been doing this exact thing for about a year. See your pediatrician and ask for an Xray. He was holding in his bowel movements and so when he finally DID have one, his rectal muscles were so stretched out that he couldn't feel when he had to go and would have accidents.
The X-ray for my son revealed almost total blockage in his intestines, and they prescribed Miralax (a laxative). This is a powder you mix into his drinks in the morning and evening. The way it's made, it will not absorb into his system and dehydrate him like other laxatives will, so it's completely safe for children. There are some kids with developmental disabilities who take it their whole lives, so not to worry.
We were also told to give him Colace (sp?) for the first two weeks, which is a stool softener, just to get things moving. They also suggested an enema on the first day. Treatment should last at LEAST three months, even though you will start seeing an improvement after only about four weeks. Stick it out for the whole time, so his body can completely get back on track. Stopping too soon will just bring it back again.
Also, be prepared for lots of accidents. Since his muscles and nerves are stretched out, he can't tell when he needs to use the toilet, and this is NOT HIS FAULT. We'd send our son to the toilet for ten minutes at a time three times a day for the first month, and the second and third months we did it twice a day. We just hit the four-month mark, and he's finally starting to be able to feel when he needs to go again.
Good luck with this. I know how absolutely frustrating this is. I hope things clear up soon. :)