In my opionion, the best option would be to configure you e-stop button as a trigger.
https://duet3d.dozuki.com/Wiki/Connecting_an_Emergency_Stop#Section_Making_a_button_do_what_you_want
You could use M581 to configure an external trigger binded to a trigger#.g macro. The macro would be triggered by your e-stop and run the piece of gcode, in wich you may put a pause/stop command and a M18 to turn off each motor so they will move freely.
I'm not sure, but I think with M18 the firmware simply sets the enable pin to the stepper drivers as low, so only the power between drivers and motors is cut.
If you are ok with it you only need to wire the endstop to a IO pin or to a not used endstop pin.