1) I gather the Prime Minister must be a Member of Parliament (as indeed must be all heads of the executive departments). How is this rule enforced in the absence of a written Constitution?
The PM is appointed by the Queen (or King); Tradition dictates that she first offers the job to the leader of the party with the largest number of seats in the Commons; If that leader declines, or if two parties have an equal number of seats, she is expected to offer the role to whomever she believes is most likely to be able to command the confidence of the house. But in law, she may appoint anyone she wishes.
It's one of those quaint little arrangements that has existed since the Civil Wars of the 1640s: The monarch agrees to appoint as PM the person most able to gain the support of parliament, and in return parliament agrees not to have the monarch beheaded in Whitehall.
If her appointed PM loses a vote of no confidence in the Commons, then they are expected to step down, and a general election is called.
2) Opposition parties have a "shadow cabinet". If the opposition takes power, is there anything beyond custom to ensure that, say, the Shadow Chancellor becomes the Chancellor?
No. The new PM has the right to choose any cabinet members he wants to head each of the departments, and to change this cabinet at any time.
Of course, the leader of the opposition can also change his shadow cabinet at any time, so it would be strange to sack a shadow chancellor during the transition to government - although it might be necessary if the shadow chancellor had lost his seat during the election that led to the change in government.
Cabinet ministers need not be elected MPs from the commons - They can also be appointed from the unelected House of Lords.
The last PM who governed from the Lords was Robert Cecil, Marquess of Salisbury, who retired in 1902; However when Harold Macmillan resigned as PM in October 1963, the new leader of the Conservative Party, Sir Alec, 14th Earl of Home, became the new PM. As parliament wasn't in session, he did not lead the government from the Lords; Instead he resigned his peerage on 23 October, in order to be eligible to run for a Commons seat in the 7th of November by-election for the seat of Kinross and West Perthshire (which he won).
Sir Alec Douglas-Home was, as a result, Prime Minister of the United Kingdom of Great Britain and Northern Ireland for two weeks, while not a member of either the Lords or the Commons.