Many easy(ish) ways to do this- the most common way is relay's activated by reed switches, track breaks or more advance methods such as IR.
Richards "Masterswitches" are very good for this & contain many circuit diagrams - see his website for further details.
They are available from Bromsgrove or (shameless plug) - us, as in Euroscale.