It's very difficult to give a straightforward answer, the problem is that many bits of legislation may apply, including the Caravan Sites & Control of Development Act, and more recent legislation covering gypsies and travellers. A motorhome or campervan can be classed in law as a 'caravan', sleeping in it may be regarded as 'human habitation' which is covered by the Caravan Sites & Control of Development Act, we have a resume of the requirements of the Act in our Motorhome Stopovers section here. Other than that, as far a we have been able to discover, there is no specific UK legislation which would make it illegal to sleep a vehicle at the roadside.
Our interpretation of the law is that you cannot 'camp' on land in England & Wales (the law may be different in Scotland and N. Ireland) without the permission of the land owner. As far as the highway is concerned (this includes lay-bys) the land owner is normally the local authority.
However, whether you are moved on or not will depend on the attitude of the local authority or the local police. Our opinion (and it is only an opinion) is that you are unlikely to be moved on if: The vehicle is not causing an obstruction (but remember that there is no 'right' to park any vehicle on the road); there is no specific local by-law or Traffic Regulation Order prohibiting overnight parking or sleeping in vehicles; you are not in the same place for more than a day or two.
Staying overnight in car parks can be more problematic. Most local authority operated car parks are covered by off-street parking places Traffic Regulation Orders, these lay down the rules which apply to the use of the car park and they generally have a clause prohibiting sleeping, camping and cooking. There may also be clauses specifying the maximum vehicle weight, classes of vehicle, etc that are permitted to use the car park. It might be argued that any restrictions not posted at the car park itself cannot be enforced - it pays to read the signage carefully, and then make a personal decision. Car parks in our listing have no such restrictions (or the local authority have told us that they are not enforced) as far as we have been able to ascertain. Traffic Regulation Orders for many local authorities can be found here: tro.trafficpenaltytribunal.gov.uk
We don't encourage overnight parking other than at approved stopovers (sometimes known as 'wild camping'), however we know that many people prefer it. Anyone considering it must be aware of the risks involved, and must have a responsible attitude to the local environment and other users of the location. As the old saying goes: 'Leave nothing but footprints, take nothing but photographs'. We know of several locations formerly used for overnight parking, that have been closed to all motorhome users because of the irresponsible actions of a minority.
For what it's worth, during our more than 30 years of ownership of campers and motorhomes we have never been moved on from any lay-by or roadside stopping place in the UK - but we normally only use them as an overnight stop on a long journey.
Many countries in Europe have networks of approved stopovers for motorhomes and there are moves to establish a similar provision in the UK. Some councils are starting to make provision for overnight stays by motorhomes, see this page for a listing of all the approved stopovers we know about.