All the deities are a form of God; however those who don't know it and worship the deities, they go to heaven and are a part of the cycle of life and death. However, those who do know that all deities are a form of God and then worship them without expecting anything in return, get united with God. Thus, one who serves any deity, teacher, ascetic, mother-father, guest, the unfortunate or any other being taking them to be a form of God is serving God.
Some people worship a deity, follow the rules prescribed for a particular ritual for that deity, sing their hymns, etc. As a result of this worship, they gain that which was the purpose of their worship. Some people worship their ancestors (pitra), perform ceremonies in their honor and follow certain rituals for them; after death they go to their ancestors. Neither of the above is bad; if they're done with some expectation then they provide the fruit at the end and nullifies. However, if they're done without any desires then they facilitate one's way to God.
Worshipping of ghosts and dead bodies is however not good, because it's considered the dark world and results in evil, so one must not do it.
Those who worship God, without any desires, submit all their work to him, meditate about him and perform various devotion-related functions, go to the divine world of His. Hence they attain moksha - freedom from this world forever.