The key word in your questions is "legally" and the answer to your question may depend on the language in your lease. If you will only be a holdover tenant for three weeks then you will be out before your landlord could force you out by eviction. The landlord will not be able to lawfully change your locks and if he does this is called "self-help". He could be liable to you for any damages caused by a lock change.
The security deposit is another issue. If your landlord is in bankruptcy you have a claim against him for the return of your security deposit. How did he identify his relationship with you on his Schedule G (for leases)? Also, did he state in his Statement of Financial Affairs that he is holding money for another party as a security deposit? His responses and itemizations in his bankruptcy paperwork may dictate what you need to do to protect your interests.
Provided you are out by the 3rd week in September and he is holding money for a security deposit, do not pay him anythign else for September.
You have a lot of good questions. Congratulations on purchasing a new home. Let me answer/provide my thoughts to each of your questions separately.
1. If your lease ends on August 31, 2010, then you are not legally entitled to be in the unit after that date. If you remain in the unit after the termination of your tenancy, the landlord has the right to file an eviction action against you in court.
2. The landlord can not change the locks on you - - that is an illegal eviction, and there are civil and potentially criminal penalties for such conduct. Only a court can evict you.
3. The eviction process can take from three weeks to nearly two months depending upon your level of knowledge of tenant-landlord laws and process.
4. I do not think that the commencement of an eviction action will have any impact on your credit or ability to purchase a home - - but a judgment against you may.
If I were you, I would speak with an attorney. There are a lot of moving parts here.