老外 (lǎowài), literally meaning "old foreigner", is one of many words Chinese people use to refer to foreigners. Compared with 外国人 (wàiguórén, "foreign country person"), 外人 (wàirén, "foreign person") and 洋人 (yángrén, "foreign person"), lǎowài is basically a more informal way of expressing the same thing. While it does have further meaning, it is used throughout this FAQ to describe any foreign person living in China.
Generally speaking foreigners should not refer to themselves as lǎowài, but rather one of the more formal terms above (usually wàiguórén).
While some foreigners believe lǎowài to be a disparaging or even derogatory term, to the average Chinese person it is a neutral, informal word with no pejorative sense. Like any other word, however, it can be used as a slur - but generally it's fairly obvious from the enunciation and accompanying sneer that it is meant as one.
Being called a lǎowài in China should not be viewed as an equivalent to being called gaijin by a Japanese person, which often has a pejorative aspect or implication that a person is not only from a foreign country, but a permanent 'outsider' to their culture. Similarly, the Cantonese gweilo (literally "ghost man"), has mostly negative connotations.
For a great article explaining the nuances of the term in further detail, see this entry on Language Log.