When a child does that in a store you quietly and without fuss take him out to the car , if you have others with you they can stay with him in the car and you go back to shopping if not ,curtail the shopping and go another day without him.Do not take him and tell him why.If he is used to getting gifts all the time when you shop thyis is why he has done it.If you think he is spoiled rotten, try taking him out to parks and Beaches and places where no gifts are involved, get Dad involved in sports or another male member of the Family , less materialism will make him appreciate when he does get something.
I think you have to make sure that what you mean by grateful is being grateful appropriate to his age. A child throwing a tantrum in a store over getting a toy does not seem like strange behavior to me, as long as it is not constant.
The best way you can teach your child good manners is to show good manners. If you are grateful for what you have, he will learn to be grateful for what he has. But he is 5, good manners are not the foremost thing on his mind so you have to allow him to also be a selfish kid. A kid at this age cannot take care of his things the same way an adult can.
Try to exhibit the behavior you want your son to pick up but also understand that he is a child and not always able to show or control his emotions in the way adults can.