The full explanation of Star Wars ‘Force Ghosts’ can be patchy post-prequels, so Mos Eisley Spaceport attempted to explain the whole thing…
Becoming a Force ghost involves transcending from the Living Force and the Cosmic Force, enabling a Jedi to effectively live on through the Force after their physical death.
This results in the Jedi’s body disappearing on their death or when they choose to transcend. However, this technique is only possible for light-side Jedi and not for Force users that have succumbed to the dark-side.
The first Jedi to transcend to the Cosmic Force was Obi-Wan’s master, Qui-Gon Jinn. However, Qui-Gon did not perfect the technique before his death, so he was only able to project his voice through the Force. This is also why Qui-Gon’s body did not disappear when he died in Obi-Wans arms. He learned this from the Force Priestesses, who come from the same planet where midi-chlorians are said to have originated.
After Qui-Gon’s death, he spoke to Yoda and Obi-Wan, and taught them the technique. This is how both Obi-Wan and Yoda were able to transform into Force Ghosts after their deaths.
Yoda: “Show yourself, can you?”
Qui-Gon Jinn: “I cannot. My training was incomplete. All energy from the Living Force, from all things that have ever lived, feeds into the Cosmic Force, binding everything and communicating to us through the midi-chlorians. Because of this, I can speak to you now.”
Before leaving for Tatooine in exile, Yoda told Obi-Wan he would teach him how to listen to Qui-Gon through the Force.
The Original Trilogy
When Obi-Wan Kenobi found himself face to face with Darth Vader, his old student Anakin Skywalker, Kenobi saw more benefit in using that moment to transcend to the Cosmic Force. It had appeared to everyone else that Obi-Wan had been killed by Vader.
There were multiple benefits for Obi-Wan choosing to do this, the distraction helped Luke and the others escape the Death Star and as a Force Ghost Obi-Wan could guide Luke. Obi-Wan helps Luke during the Battle of Yavin at the pivotal moment when Luke decides to use the Force instead of the targeting computer to destroy the Death Star.
It is also possible Obi-Wan or Yoda or Qui-Gon foresaw Anakin overthrow the Emperor, knowing he was the chosen one, Obi Wan was reluctant to kill Vader.
But what of Anakin’s Force Ghost?
During the victory party in the Ewok village, why does Anakin Skywalker’s Force Ghost appear and why is it the younger version of him?
When Vader struck his old master Kenobi down, he must have been puzzled as to what had happened to Kenobi’s body. It is likely he performed his own research and studied the technique. He would also have learned that he would not be able to use the technique as a Sith, unless he returned to the light. It is likely the Emperor was also aware of this technique, but Darth Sidious obviously had no intent on returning to the light.
After overthrowing the Emperor and bringing balance to the Force, Vader had redeemed himself and had returned to the light as Anakin Skywalker.
Therefore Anakin was able to transcend to the Cosmic Force on his death and although we don’t see his body disappear, we have to assume that it did shortly after he died. Luke then returned to Endor and built a funeral pyre with Vader’s empty armor.
The fact Anakin chose his younger self to be presented as his Force Ghost implies that on returning to the light, Anakin did not want to be remembered as his evil older self that was enthralled to Darth Sidious choosing to be remembered when he was most happy with Padme.