If the property is covered by the San Francisco Rent Ordinance, your landlord or the new owner cannot evict you without paying the applicable relocation expenses. If the landlord has been making unnecessary inspections and is constantly coming to your home, it could be a breach of the covenant of quiet enjoyment and may also be a violation of the Rent Ordinance. Additionally, once an owner move-in eviction has been done on the property, another owner cannot come in later and perform a subsequent OMI. Feel free to contact our office for a free, no obligation consultation.
Disclaimer: You should discuss your situation with a local attorney, as the above statement is a general overview and does not take into account all of the factual considerations in your case. Nothing in this statement creates an attorney-client relationship.
As long as he gives you the key he can change the lock if he sees fit. Periodically upgrading locks and fixtures is probably a good thing and not subject to your permission.
I can't believe things are that bad if you stayed 13 years. The new owner will take the property subject to your lease, but can evict you at the termination of it.