Another critical thing to be aware of when buying a foreclosure is that you don't get clear title until the one-year anniversary of the property being sold on the courthouse steps (i.e. foreclosure sale).
You'd have to keep detailed records of everything you did to the house to make it safe to occupy. Things like changing out functional countertops with granite may not be considered a reimbursable expense if it was a preference change. But fixing the roof, replacing appliances that weren't working or unsafe, replacing carpet that was beyond salvage, etc., are examples of things that should be reimbursable, but you have to prove it was necessary. So take lots of pictures of the before to back up your case.
The longer a property has been on the market, the less likely you would have to give up your home. But it does happen, although very rarely. You basically have to ask yourself if you are willing to risk being one of the very few that it does happen to.
Also, don't assume foreclosures are the best deals. It can be worth paying a little more to own it with a clear title from day one.
Give me a call if I can help you with your home search.