They can apply for a permanent green card to stay as guest workers or go home and apply for legal immigration leading to citizenship. Not both.
Applications would be granted on a one to one ratio as undesirables are deported. Start with the gang bangers and serious criminals. Work your way up to the petty criminals and social service consumers (but I repeat myself).
Those who fall in between would have to determine if they are a candidate for a permanent green card or for deportation. Many would self-deport, giving us a manageable number to work with.
User fees from the successful permanent green card applicants would be used to pay for deportation of the undesirables, including voluntary repatriation.
Those who want to transform America into another Latin American style third world kleptocracy are fond of saying your can't deport everybody. What they really mean is that they don't want us to deport anybody.
Excellent supporting comments.
If I wanted to live in Mexico, I would have moved here. Some of the support that the leftists in this country give to the chaos of uncontrolled immigration caused by our open border is just the projection of self-loathing. If we do not gain control of our borders we are doomed.
I would suggest reading The Camp of the Saints by Jean Raspail. This is the fictional future of Europe that becomes beset by boatloads of third-world people that it cannot show the courage to prevent from entry let alone eject. Uncontrolled immigration is a form of cultural suicide.
ref: http://en.wikipedia.org/wiki/The_Camp_of_the_Saints