The correct way to ask your question would be: "What should I say to be polite when greeting others?"
To answer your question:
I think it is perfectly fine to say any of the following. These would all seem polite/mostly formal to me:
1. Hello.
2. Hello, how are you?
3. Good morning. (perhaps a little more formal)
4. Good evening. (perhaps a little more formal)
etc.
Now the following would be informal:
1. Hi
2. Hey
3. Hi, how are you/ya?
4. Hey, how are you/ya?
5. Hey, how are you doing?
etc.
*********************************************************
Added comments:
*"Hi," in my experience, is too short/curt to be considered formal. (but this is only an opinion)
*Now, I know for a fact that "Good morning" is perfectly acceptable to use when saying hello during the morning hours. (I use this phrase every day when greeting my students during morning classes right up until noon.) It is not accurate to limit "good morning" to only those who have just woken up .
Source: myself, American English