Wai Guo Ren is the formal, written form to describe a person with a nationality other than China. Lao Wai is a oral term to call them.

Above photo is the sample of Chinese PR ID. Although the English part says “foreign”, the Chinese part clearly says “外国人/Foreigner”.
To understand what exactly 老外/Laowai means, I shall introduce you some other Chinese words, please pay attention to the character 老/Lao:
老婆 Wife
老公 Husband
老板 Boss
老弟 Bro (younger)
老哥 Bro (older)
老妈 Mom
老爸 Dad
老兄 Dude or Bro (older)
老大 oldest child in a family or person in a group
老二 second oldest
老广 Cantonese people
老陕 people from Shanxi
老师 Teacher
老乡 people from the same hometown
老天 god (in general)
老爷 lord/master
老铁 bestie
老子 I (in a rude way, and is not the Lao-tzu/老子.
It’s just a habit of Chinese language to define relationship with a person with 老 at the beginning. It usually means closer relation and sometimes respect in either formal or casual form.
If sometimes someone does speak it out in a pejorative way, it must because of the sarcasm tone. The word itself is almost impossible to be pejorative in Chinese language.