in some context, they are interchangeable while in other context, they are not."waiguo" means "foreign country/countries", whereas "guowai" means "outside your home country". "waiguo" is normally used as adjective, like waiguoren (foreigner) ore waiguohuo (foreign products). "guo wai" is a prepositional phrase, following verbs, like i live in guowai; i went guowai.
e.g. i live in "waiguo", emphasizing it is a foreign country that you're living in, while i live in "guowai", emphasize the fact that you are not living in your home country, but "i live in "guowai" is used more commonly.
when you refere to the people, foreigners, you can only say "waiguoren". we don't say "guowairen".
in most circumstances, they are interchangeable and can be understood well.