An excellent summary of what the Prime Minister is, is to be found here:
http://en.wikipedia.org/wiki/Prime_M...United_Kingdom
The PM has to be a member of Parliament by convention, but not by any written law. He could conceivably remain PM long enough for Labour to elect a new leader, should he lose his seat, and would not break any law in doing so.