Hi, J.,
I haven't read any responses yet, so I'm sorry if I am repeating anyone else's advice.
I wonder if you are inadvertently reinforcing your child to continue this behavior by sometimes responding to him. It doesn't matter if you DON'T respond to him 100 times and then the 101st time you do, you WILL reinforce that behavior. That is also the strongest form of reinforcement, called intermittent reinforcement. Think of the slot machine. Most people rarely get a pay-off. But the intermittent reward reinforces people to continue to pull that handle again and again, despite losing more times than not, in the hope that the next pull will result in a win finally.
If you want to stop this behavior, you MUST NOT respond, even if he tantrums for a long period of time. Just to warn you, the behavior may get worse initially as he may try to test it out to see if you will cave and if you really mean it. If you grit your teeth and ride through that, you WILL eventually extinguish this behavior in him!
When he is calmer (and ONLY when!), then you could sit down with him and reflect the feelings you saw him express to convey understanding to him and acceptance that he is still loved when he's feeling at his worst. This will also help to re-establish a good connection between you two after episodes that just in all honesty feel horrible!
Hope that helps!
Sincerely,
S. M. Wolf, M.A.
Licensed Marriage & Family Therapist
Anaheim, CA