You need to explore the retroarch.cfg files (RetroPie/configs/…) for each of the emulators. You will options for setting functions such as quitting the emulator, saving your game, and more.
You have to take into account some things. First, not all emulators work through the Retroarch core, so you will have to search for said emulators config files in the folder system to try to set up the desired functions. Second, if you don´t want all emulators that run through Retroarch to use the same key for quitting, then you will have to modify the individual cfg files for each emulator (or at least, the differential ones).
Also, search around the forum, there is definitely a lot of threads about this subject.