This shouldn't come as a surprise as the banks notify the occupants very well over the course of many months.
You do have rights as a tenant though and need to be made aware , right away.
But you can buy it after the Foreclosure, when it becomes an REO.
Realistically, you are looking at 3 months or maybe 12, (the speed with which the banks moving now).
Take the money and run.
Save everything you can; give up pizza and movies!
Connect with a Realtor and have him watch for the LISTING to appear.
Good luck and may God bless
Hope that helps.