Unless your employer explicitly forbids outside work (most don't, I think Google does), why wouldn't it be legal?!
In California, incorporating with an LLC costs $800/year and provides little to no benefit. It specifically does not provide much legal cover if you're a one-person corp.
On the other hand, it's easy and free to set up a "sole proprietorship" with the IRS, and register some snazzy name at your county registrar. This is the path I took, and I recommend it. (Nolo Press is a good resource for many basic legal things.)