How long did you actually try to get him in underwear? I would try underwear...not naked but underwear so he feels the wetness or poop...and stick it out for at least a week but probably just permanently. I understand some kids get really constipated because they hold their poo for days when toilet training and your boy may be one of them. I would start a separate google /forum search or new thread on that b/c it's more common and you may get better advice just about that issue. But I bet after a few days/weeks of peeing himself he'll get sick of it and start using the toilet. Also, he will feel it if you are firm and mean business and that he is NOT going back into diapers. Before he may have sensed that you were going to cave and give him a diaper again, so he just held out (literally!). Make it clear he is now wearing underwear and there's no going back to diapers (during the day). It may be a rough and messy week (roll up/cover carpets and furniture or be outside a lot) but I bet he'll come through alright and using the toilet. He may be able to hold his poop but a human can only hold pee so long before it comes out. Make sure he keeps drinking!
BTW I started a thread recently about my own four year old, resistant toilet trainer. We have had a lot of luck by just getting very firm (staying loving but just standing firm) and being 100% clear that it's not an option anymore and this is the way it is. He protested a lot at first but it was literally like one hour before he realized we weren't budging and he accepted it not only without complaining but with pride at what he can do! We are going gradually....now he's in pull-ups and managing his own diaper changes in the bathroom, and sitting on the toilet twice a day. In a couple weeks we're making the big switch to underwear and I suspect it'll be the same story: protest at first but acceptance once he sees we mean business. The big difference for us was being 100% clear and standing strong, and being matter-of-fact: "This is the way it is now"...while staying calm and loving. Before he sensed we were not totally clear and would let him stay in diapers if he really wanted. But now that we made a clear decision he is going along with it....even with some protest at first, he got through that and now it's going according to plan.
Best of luck, I totally understand the frustration!!!
Mama since 2010
Multicultural living in Europe