my kid also started doing the "THROW MY HEAD BACK AS HARD AS I CAN BECAUSE I'M PISSED" thing. He's smashed himself a few times a little bit doing that. I try to stop that behavior by gently throwing him on the ground when he does it but he's too smart for that.
Mine did that so I would firmly plant my hand on his forehead against the wall not allowing him to do so and just sternly said no. Hold eye contact and when he tries to do it and your hand won't allow him to he will soon enough learn.
The thing with boys that my dad did and I tried to repeat is that just the tiniest bit of physicality in their life lets them realize that you are serious, they could never beat you, but you are stronger than anything else so you can protect them.
It also helped when we had a few close calls when doing work on the house. My dad had to toss me aside a few times to prevent me from being hurt, adjusting beams for load bearing walls to remove, replacing 10 foot tall windows, and working inside the breaker box to the house are all events that come to mind. I knew that if he was doing something physical like that it was for my own good, it was never out of anger, it was to let me know I was in danger of doing something wrong or had already crossed that line and needed to be reset to center.
I have had to do the same to my son as well here and there. He would tip in his high chair when he was 3 and he tipped all the way over once, I saw it happening and jumped up as he was falling. He was strapped in and couldn't go anywhere. I cradled the chair all the way done so his head just touched the wall behind where he was sitting and then 'saved' him. He was beyond scared and got his head bumped a little but dad was there to save him. I made it sound like if I wasn't there he could have died. My wife played along, now dad was always there to protect him. He mouthed off to his mom a few months ago and was being a little shit. I moved with a quickness like a mongoose and he thought dad was slow. I saw that he was close enough to the wall so I placed my hand firmly on his sternum and backed him up to the wall. Didn't throw him and didn't hurt him in any way but the shock of it was quite enough. He realized quick that you don't be a total shit to your mother. Didn't hurt him and we talked about it immediately after we resolved mom's issue.
The role of a father is different for all of us and I know putting your hands on a child at all is a touchy subject. I feel my dad did it well without ever hurting me intentionally and not once did he touch me in anger. I try to do the same and so far I feel it has worked out great. My mother is a different story, she spanked me and sometimes I feel it was out of malice. She has since admitted that she had no clue what she was doing with boys and we were adopted at age 5 and 6 so by that time she was playing catch up.
TL;DR - Use the wall for head throw backs and not the floor, make eye contact, say no firmly.