In my experience, there is no such thing as getting them to match exactly. However, you would want to strive to be as close to that as possible.
The first site you set-up test/live will depend on any number of factors, but once you have one set-up, you can easily use it to set up the other. I keep a running log of any modifications, host settings, or site settings that I change. However that is not always necessary to keep track of.
Once you have the other site set-up to match the other as much as possible, (things like your web.config must be different), you will need to synchronize the database and the file system. Everything else should maintain itself.
Synchronization of the database should be pushed from the live site to the development site. NEVER the other way around. There are tools to help keep it synchronized, but I do not know of any free ones. As far as I know, Red Gate has some of the best tools out there. Otherwise, you are stuck with the manual backup and restore method, which can be eased using a backup file and filesystem approach combined with a T-SQL restore job.
The file system can be done manually, using a batch file, or using software. I prefer the free approach of using WinMerge to synchronize file systems.