The Prodigal Academic has a great post on alternate careers for scientists outside of academia. I'd also like to add a few notes on CS/Engineering research jobs specifically.
Beyond what Prodigal mentioned, quite a few places support academic style CS/Eng specific research. Depending on what area you work in, you might be happy at places like IBM Almaden, SRI, Google, PARC, Microsoft Research, Apple, Intel, and Disney. There are also quite a few academic/research lab hybrids, like the Johns Hopkins Applied Phyiscs Lab (APL) and the Univ. of Washington APL.
I get the impression it can be tough to get your foot in the door at some of these places, but once you do you can often get something like tenure. Particularly older, well-established and well-managed companies are less likely to do layoffs I would think. This is especially true at non-profits/national labs (e.g., Hopkins APL), or at the "we don't need to make a profit right now because we have lots of cash" companies, like Microsoft Research or Google.
The cultures at these organizations can vary dramatically in how they support your research. For example, I had one colleague who did systems research at Apple but had to take vacation time and pay his own way to attend conferences. Whereas I knew someone who worked at a small company and she could go to as many conferences as she wanted, and get paid for it.
Another issue is publishing. For example, Microsoft Research and parts of IBM are big into academic publishing, whereas SRI is probably less so in general. This is something worth checking on if you want to publish. Same for open source code. You might need to go through a three month approval process to put a little perl script on your webpage, or submit a paper to a conference/journal.
If you interview at these places, even if the job title is something like, "Research Scientist", have them make clear exactly what expectations will be placed on you. Sometimes even a fancy title and gobs of money still means code monkey. It's better to know that going in - you don't want to expect to be leading research team and find out you're the new database programmer for someone else's pet project. And the job ad may or may not clue you in to these expectations, so it's best to ask.
Also check what they mean exactly when they say "flexible working hours". At some places this means you can come to work any time between 6:30am- 8:30am. Some places have a vaguely worded policy that leaves it to the discretion of your manager. Some places let you telecommute every day and just come in for meetings. In any case, also good to know in advance.
If you plan to do research at these places, it's helpful to know what it is you'll need to facilitate your work and what they already have. Do you need specific equipment? Animals? Human subjects? Even if you're joining an existing lab with existing equipment, you'll want to make sure you have access to it when you need it. Do you need to book the Cray eight months in advance? Will you have funds to pay human subjects or do you need to get grants first?
And on that note, what sort of support will you have? This also ties into expectations - yours and theirs. Maybe they'll give you a group of people who will work on your project part or full time. Do you need to bring in grants to cover their salary? Are you evaluated solely on the amount of external/internal research funds you bring in?
Just like with an academic job, do your homework, ask questions, and don't be afraid to negotiate for the things you need to be happy. I think the aforementioned organizations and the ones mentioned in Prodigal's post can be great places to work, but may take some maneuvering to be like what you imagine.