The trick is to register an LLC, and then get your employer to outsource the work to your consulting company. You get laid off, and then continue to work through your company.
Only mild sarcasm, as this is essentially what happens.