They are still trying to figure out how they feel. They do not understand their feelings, so you need to give them the words.
"You seem angry." "You seem frustrated." "You seem tired." Just pick the one you think your child is feeling.
Then you need to give them a big hug and tell them, "you need some quiet time. Do you want to sit in the chair quietly or in your room quietly."
Then place them there till they can calm down. Do this every time.
If they start to throw themselves on the floor like a tantrum. Do not say a word, step over them and leave the room. If you are out in public like a store and they throw a tantrum. Do not say a word, pick up your child and put them in your car and go straight home.
Tell them that they cannot go back to the store till they do not throw fits. Do this every time. They will learn that you will not put up with this behavior/.
You are the adult, you do not get pulled into their emotions. They need you to be strong and show correct behavior.
Sometimes if my daughter was on my last nerve, I would put myself in time out and tell her "Mommy is frustrated and need a time out."