When I've run into this in the past, it's because IIS has a lock on the file and it can't be overwritten at that moment. Two ways you can go, you can publish an app_offline.htm file right before the deploy. That should cause the entire app domain to be unloaded. Or, stop the app pool, deploy the application then start it again.
As for how to do it from TeamCity, that maybe a little tricky. But if you can use msdeploy.exe you can use the command to publish a app_offline.htm with a simple command. Or if you want to take the app pool offline, the recycleApp provider should work.