Gandalf was a Maiar, a powerful spiritual being related to the Valar, so he cannot die. After his body was destroyed in the battle with the Balrog, his spirit went back to Valinor. Seeing that his work was not done and the One Ring was yet to be destroyed, he was sent back by the leaders of the Valar. He was allowed more power than he previously had, even more than Saruman's at his peak.