Where does "Yeah right" come from? Can it be used in a formal writing? If not, what is a good alternative?
"Yeah, right!" is an example of irony. Irony is the use of a word or phrase to mean exactly the opposite of its literal sense. Here it would also qualify as sarcasm. It would be understood to mean "No f@$*ing way!"
You would definitely not use it in formal writing, unless that composition was a treatise on slang or some other academic discourse on language.
There's also a joke (that as far as I know can be applied to other languages as well with similar constructions; the Greek equivalent «Ναι, καλά» comes to mind for some strange reason :) where the teacher explains that there are times and languages where a double-negative has positive meaning ("Can't say I didn't see you") or it can keep a negative meaning ("Haven't done nothin!"), but there is no known case of a double-positive having a negative meaning, at which point the smart-alec of the class says:
could also be interpreted as another variation of
It entirely depends on inflection when speaking. When written, if the ending punctuation is an exclamation
you could infer the meaning to be ironic, whereas if the ending punctuation was a question mark
you could infer the acceptance-seeking meaning.
Regardless, neither is appropriate for formal writing.