HMRC has extensive information on their web site about these topics.
link is
http://www.hmrc.gov.uk/incometax/tax-leave-uk.htm

The information may be little confusing but read through it eventually it makes sense. You do need to fill few HMRC forms before you leave