I don't think that Yoda and Obi-Wan taught Anakin how to retain his identity, he did that on his own when he gave his life to save his son and for the greater good of all beings in the galaxy.
I think the intention is that Yoda and Obi-Wan were able to help Anakin become one with the Force before he actually expired. He loses consciousness in front of Luke, but off camera, before he actually dies, Obi-Wan and Anakin assist him in becoming one with the Force.