Some years ago a former co-student from Oosaka taught me the expression なんでやねん. He said it is Oosaka slang and it could be used in all kinds of funny or awkward situations, meaning something along the line of "What the hell?". However I dimly remember to have read somewhere else that this expression can be offending or inappropriate.
So my questions are:
What does this expression literally mean?
In what situations (business, friends, ...) and which places (only in Oosaka, other places in Japan) can it safely be used to get a comical effect?