The Lisbon Treaty (which has been in force since December 2009), incorporated into the Treaty on European Union a clause allowing for the exit of a Member State from the Union (in article 50 of the TEU).
Under that article 50:
The State which has decided to leave the Union must notify the European Council of its intention and negotiate an agreement setting out the framework for its future relationship with the Union; and
The formal exit notification has no immediate impact on the legal arrangements between the United Kingdom and the European Union. Its effects will come into force after at least two years, and this period may even be extended by mutual agreement if more time is required to negotiate the terms of the exit.
For the entire period over which the United Kingdom’s exit is being negotiated, it will continue to be a European Union member to all intents and purposes and retain all the rights and obligations inherent in membership. All rules of European Union Law will continue to be applicable to United Kingdom residents.
The negotiations between the European Union (or EU), represented by the Commission, and the United Kingdom (or UK) will need to deal with the legislation on every area affected by EU Law—such as state aid, competition or extradition procedures—including taxation. Once the exit agreement has been reached, it will not need to be approved by all the EU Member States, only the approval of the European Union institutions being required.
There is therefore a chance that the United Kingdom will use the exit negotiations to reach a trade agreement allowing for freedom of movement of capital and free trade, in the style not only of the agreements which the European Union has traditionally held with the countries of the European Economic Area, but also of those recently signed by it with Canada or South Korea, or of the terms on taxation reflected in article 15 of the agreement with Switzerland.