What I've always been told by friends of mine who are personal trainers is that it's best to put on a bit of extra muscle first, and then cut down your body fat to where you want to be. Through weight-loss, you'll always lose some lean mass, no matter how great your diet or program. When putting on muscle, it's also very hard to put on only muscle without any fat. Therefore it's better to bulk up a little bit extra in the beginning, and then not be so worried about losing that extra muscle when you're decreasing your body fat.
It's pretty simple actually:
-Gaining weight means you consume more calories than you burn. Not all of those calories can be stored as muscle, no matter what you do.
-Losing weight means you burn more calories than you consume, causing the body to deplete it's extra stores. Not all of the stores depleted will be fat, some will be protein.