How Edward managed to escape from Gluttony?
Gluttony was created to be a second Gate of Truth but is only a failed copy. Ed had the idea that because they came there through the failed gate, they must be able to get back trough the real gate. It's just like creating a door back to Gluttony.

To open the Gate of Truth, he used Envys Philisopher's Stone and the old parts of the Xerxes mural to make this special human transmutation. The sacrifice for opening the gate was a soul of the Philisopher's Stone, which thanked him afterwards (because he freed the soul).