This is a response I wrote for another family, that will help you.
Take 20 uninterrupted, totally involved completely focused undistracted, minutes doing activities your child completely loves to do. Do this daily. Be present, so don't have food cooking, or laundry on, it's about him and you connecting. Follow his lead, have fun, let go. Do this every single day. Let him know how much you enjoyed it , how you can't wait to have one to one time everyday. Instead of yelling, use a calm voice when speaking with him. Stop the show. With no audience, there's really no point of having a show. You may want to child proof before doing this, but when he gets out of control you want to disconnect. You want to be neutral and matter of fact about it. Be quick about it and non reactive . Tell him you will be going to your time out spot and that he can come find you as soon as he is less excited. Nothing more. And leave. Now wait. When he comes, tell him you need a hug. Hug it out. Tell him that you're changing time out to make it a quiet place he can go to alone or with you when he feels really excited or angry. You can remind him of this when he needs it. He can go with you or alone. You will say something like I see you're really excited, do you want to take a break in your quiet spot or do you want mommy to come too. The spot can have books, music, favorite game or toy, no electronic devices like tablets or tv though. It can be decorated any way he wants. A huge box is a good thing to use. Make a little house of it. Or use a sheet to build a tent.
If he does this when he feels excited or anxious, or angry, discuss with him what other things can HE CAN do when he feels this way... like take a walk, build Legos, paint/color, stomp on his pillows, big self hug, take a deep breath, count to ten, go to his quiet spot, read a book with Parent, use flashlight in the dark (not really dark not to scare him). Just some suggestions. Stop yelling, reprimanding, and time- outing. It is feeding into his needs for attention and power negatively. That all can be replaced with the Positive version as described above. Would like to follow up with you so let me know how things go. Best to you. Just submitted this for another family. All punishments must stop. He's trying to tell you to give him choices, to notice him, to involve him usefully. He's also trying to tell you that "you can't make him do what you want" Don't get into conflict, don't give in, just follow the steps above. But, for sure, the dynamic needs to change. Spend less time ordering, commanding, and more time being curious. Use a question instead of command. Don't back talk, you're modeling it. Take ego out of the mix... He isn't competing with you, he's communicating to you with a positive intention to feel significant and to feel belonging. A big part of that is self power. He wants choices...to be involved usefully... Let him choose between two things. Instead of put your shoes on, ask him are you gonna wear your sneakers or your crocks before going outside? Then let him get them and put them on. Which brings you to training. Training is teaching a behavior, then role playing a few times while he gets it. Keep NO out of it. Use humor. Back off to your quiet place of you get frustrated. Take turns. Remember that mistakes are great opportunities to learn and communication is only effective when you get the response you're looking for. You can also try replacing the behavior like high five instead, or walking over and saying hi, or tapping someone to get their attention. Role play those or any other ideas you may have. Remember, have fun with this, laugh, enjoy, and he will too. That will help him learn more quickly. Let me know how you do. Best to you.