J.
Hi, my son is 3.5 and has tried this - and in the heat of the moment, it's sometimes hard to remember but You're The Parent! You should not accept being spoken to by anyone like that and letting you're son get away with it is reinforcing this bad behavior. What I did when this started was quietly say "please Do Not speak to me in that manner" then I took him to his room and told him he had to stay there until he apologized to me - and I left the room. There was quite the screaming, crying drama for about 15 minutes, but I stuck to my guns - if he tried to leave his room, I just carried him back - I didn't say a word except to ask if he was ready to say "sorry". Took a few rounds, but he got the idea and said sorry - afterwards I tell him he's a good boy, but he has to not yell at Mommy.
If it's the situation where he's demanding I do something, insead of saying "please" or asking nicely, I just say "I can't hear you - I can't hear you" pretending I can't hear him, until he says "Please - ......and then whatever he's asking for." then we both usually end up giggling. Hope this helps!!