Well, when the property goes into foreclosure that means the bank owns it. The bank will sale the property for what is owed on it sometimes very cheap. They'll auction it off to the highest bidder. Your rights are zero and you should be prepared to move very soon or buy it at the auction.
If your lease agreement existed before the mortgage was contracted, the new owner cannot kick you out. If the mortgage existed before you signed the lease agreement, you are in trouble. Ultimately you will face eviction. You could eventually delay this a little, but only for a few months, if things go well. You may strike a deal with the new owner and have him pay you the amount of one or two month's rent if you leave without him starting (costly) eviction proceedings.