Sounds like you didn't let it get you completely off track, so that's actually really good! Now that you understand your trigger, you need a plan. If this ever happens again, maybe you could work off your stress some other way? How about a 20 minute walk? How about calling a friend? How about writing down why you want to lose weight and asking yourself if eating what's in the pantry going to solve anything or get you toward you goal? I try to chew gum. I also have sugar free jello when I feel snacky and I know I don't really need anything. You could also put on some music that really inspires you and just dance around. You could drink some hot tea to calm your nerves or take a hot shower or bubble bath (if you have a tub). I love to go on youtube for either music, karaoke or to watch motivational weight loss stories. You could also go online and find a dream outfit you'd want to wear once you got to goal.
You just have to figure out what will work for you and it's hard for anyone to guess, but I hope that at least one of the suggestions help.