In addition to what everyone suggested below: you ALSO need to teach him, how to communicate his emotions/wants/needs, etc. And, how to KNOW his emotions/wants/needs.
So that, the kiddo can learn to communicate it, instead of tantruming about it.
ie: From when my kids were toddlers about 2 years old, I began to teach them the words for feelings, how to tell me it, and how to know it for themselves. So that they learn, their own cues, too. And will learn about themselves.
And when my son was even 3 years old, HE could tell me how he felt. Once when he was "grumpy" I asked him "Are you irritated about something?" and he told me "No Mommy, I'm frustrated." He knew, the difference and could tell me. I also knew his cues if he was tired or hungry or just fussy. And then, he would tell me if he just wanted to be by himself, or want a hug, or was hungry, or whatever. So, communication is very helpful for a kiddo. But you have to teach them it, and the words for feelings, and even if they are grumpy or happy, that they can tell you.
If not, a kiddo gets all pent up.
From this point on as well, you need to start to teach a kid coping skills. Because, a kid WILL get grumpy or fussy. That is a given. We can't expect them to be all happy and smiley all the time. So, start to teach your kid coping skills, practicing WITH him, or role-play.
Because, punishments alone, don't teach them those "skills." You need to also teach them HOW to cope, HOW to express themselves, that they CAN tell you their irks or happiness, so that they develop... an aptitude for it. SO that, by the time they get to Elementary school/Kindergarten... they will have had, practice and skills about it, already.
Kids do not have inherent skills for handling their every emotion nor how to communicate it. Not even some adults know how to do that.
So, you need to teach a child, those things.
Because, punishments alone, don't teach a child communication or how to know their own feelings nor how to express it, nor the skills for problem solving or coping with frustrations.