He may very well have incontinence, though it's not all that common. He can try avoiding foods/drinks that contain caffeine as that relaxes the sphincter muscle. If the doctor puts him on medication, it will usually be an antipropulsive drug. Though sometimes this can be caused by an emotional response, since he may feel out of control in other areas of his life and knows he can control his bowel movements and so he poops his pants. I'd take him to another doctor to get it checked out again. good luck.
dont worry about it, its normal and more common in boys too, y four year old wont go to the toilet at school because he doesnt feel comfy doing a poo there he has to be at home, this can also be down to stress or even an argument hes heard too, i dont worry about it because its normal for kids of their age
i have worked in a daycare for almost 3 years so i see plenty of this. has anything tragic or big happened lately? divorce, new baby, move? this could alter his the pooping his pants could be a result of constipation or encropresis a.k.a stool withholding. be careful with his diet, maybe cutting out dairy. as for peeing his pants it could be a bladder infection or a yeast infection. if i were you i would take him to a pediatrician and possibly referred to a specialist. you want to find out the cause before it turns into anything serious.