"Hello" is the standard greeting. It's neither formal nor informal. It is the best one to use.
"Hi" is more informal than "hello."
"Hey" is complicated. It usually does not mean "hello," it means "pay attention." For that reason, it could possibly be rude. However, like many things, it can be used as a greeting, it's all in the tone of voice. Some typical contexts:
"Hey, excuse me, can you tell me how to get to the bus stop?"
"Hey! Shut the screen door, flies are getting in!"
"Hey, who left their lunch in the microwave?"