Writing a letter to your landlord, or property owner, objecting to the new owners attempt to terminate your lease and have you evicted after a foreclosure sale is the best path when confronted with this situation. If you rent your home or apartment then The Protecting Tenants Foreclosure Act protects you from this type of early lease termination or eviction. At a minimum you must receive 90 days notice of termination of your tenancy. And if this owner attempts to give less than 90 days you need to send a letter about the law, your lease, and how he must comply.
If you have a lease for a term, such as 6 months or a year, then the owner cannot evict you until the end of this lease term. Under law you have the right to continue occupancy until the end of that lease term; new owners acquiring homes or property through a foreclosure sale must honor existing leases.