The Nightmares were never truly "released". Instead, they were let out of their small enclosures (the cubes), and let into the larger, yet still contained, enclosure that happened to contain their victims.
Once the victims were dead, then it simply becomes a matter of getting the Nightmares onto the elevator.
As Bardo mentioned in another answer, at least some of the Nightmares had specific rituals or weaknesses.
Some likely examples:
The Japanese ghost could be contained by a ritual.
Others of the Nightmares could be overcome by brute force (the Buckners, the werewolves, and presumably the zombies and others).
the merman and the Kraken would likely return to water
the Buckners and the zombies would probably return to a grave
the Hell Lord would almost certainly go to whereever his puzzle box was. Note that he had it with him in his cell when Marty and Dana go down the elevator.
The most likely scenario seems to be that the device used to summon a specific Nightmare would be usable to also lure that Nightmare (or Nightmares) back to the containment cells.