it's called a shutdown controller, search the forum and you'll find hundreds of pages of info. it can be done lots of ways, depending on how much you want to spend on it, whether you want to build it from scratch, and how fancy you want it to be. for instance, some people do it with just relays and a few discrete components, other people use microcontrollers and such, like my design
also, you should definitely check out the thread FAQ: Do-It-Yourself Startup/Shutdown Controllers
FAQ: Do-It-Yourself Startup/Shutdown Controllers
and while you're at it, check out the rest of the stuff in the FAQ forum, there's plenty of good info there.