My oldest son had problems going poo in the potty. I basically just started taking the underwear with the poo and put it into the potty, the poo, not the underwear (although I would rinse out the unders if they were sloppy). I would flush and wave bye bye to the poo. Some kids are possesive about their BM's, after all when wearing diapers, most parents just take away the poo and put it into the trash. Now all of a sudden you want to put it into the potty? After awhile, my son started to poo in the potty once he understood that is where it goes. Your son is a quite a bit older though.
I would try a chart. After so many times going poo in the potty give a treat. Making sure to take away if he goes poo in his underwear. Have you explainded to him why the body produces waste and where it should go? My sons and I have a little chant to remember when they were little. "Poo Poo in the Potty". It is important to be consistent and not to scold.
My 3rd son has constipation issues. He had very painful BM's, so he would hold it, making it even worse. I try to use natural stuff first, eating correctly, but he wouldn't eat the things that would help. So I give him a fiber supplement in his juice. He is much better now.
You may also have your son help clean up after such a mess. I know it is more work, but if he can see how unpleasant it is to deal with in the underwear perhaps he will stop it. Also, while I don't hold with punishing, having a icky face and gagging while dealing with nastiness so they know how icky it is, is something I don't have any problem doing.