an EXCESS of calories is required to gain muscle, and a DEFICIT is required to lose fat.
Unfortunately, if it were that simple the Diet industry wouldn't be the multi-billion dollar empire it is today.
Millions of people each year go on diets following that exact same principle; thinking that if they just cut their calories they will drop bodyfat. You'd be hard pressed to find a success rate of better than 5% following this regimine. When I say success, I'm referring to lasting fat loss over a period of time greater than 1 year. In my opinon, if the fat never returns, then you can deem yourself "successful". How many days without cigarettes must you go without to be a "non-smoker"? How many days without alcohol must you go to be considered "sober"? Success can be measured in many ways.
Remember, the original trend going back to the 1970's was to reduce calories. This backfired because people didn't understand that the body will down-regulate metabolism to match. The result failure. Back to the drawing board. Then in the 80's-90's, the low fat revolution hit us. People were told to reduce their fat, and that they did. Unfortunately, the fatty snacks were replaced with sugar in the form of carbohydrate (energy bars, granola, low fat muffins, Diet drinks, etc) and the bodies natural insulin levels went up and down like a rollercoaster as fat inducing carbohydrates became the staple "diet". The result, Americans were now even fatter than ever. Failure once again. Now in the 20th century, the low carb diets are becoming popular again (they existed in the 60s'). People will ultimately fail on these diets as well if they don't improve their metabolism, and promote lasting fatloss by building additional muscle.
In my previous post I used the term "lasting" fat loss, this is important. In my opinion, anyone can lose weight, and yes, the simple mathematical formula will apply here, But......... The person who follows this type of diet for a significant period of time has a extremely high chance of lowering their metabolism, as their bodies setpoint becomes lower and lower as the body gets use to functioning with less calories. Muscle tissue is sacraficed and the result is drastically reduced metabolism. Once this person begins eating 'normally' again, the fat will come on much quicker and future fatloss will be even more difficult. This is known as "yo-yo" dieting.
The key to lasting fatloss is metabolism. Quick weightloss diets often fail in the long term - we all know the statistics. The biggest reason that they fail is that the bodies metabolism has not been given any reason to increase. Rapid weight loss is the worst thing that can happen to a metabolsim. You just can't simply fool with millions of years of evolution as far as the human body is concerned. The body is much smarter than that.
Muscle is the most metabolically active tissue you have. It requires many extra calories to maintain. The more muscle you have, the more calories you are going to burn at rest and at play - even while you sleep. Even a single pound of muscle lost will lower metabolism. Conversely, a single pound of muscle increases metabolism. Bottom line: For lasting fat loss you must preserve the muscle you have if you are fairly muscular, or build additional muscle if you are not. The latter is obviously better.
As far as the number of calories it takes to build muscle, I can tell you it vary's from person to person. It depends on many factors including natural levels of anabolic hormones in the body. For example, I can take the typical teenager who has never touched a weight, and eats the typical fast food diet, or seldom eats at all. Now, according to logic, this person who eats infrequently, possibly only 1000 calories a day of junk food, shouldn't be able to put on much muscle - but what do you know, hormomes take over and additional muscle is built rather quickly, despite the fact that he's expending well over 1000 calories a day just in maintenance.
There are numerous factors involved in the muscle building process. Factors that are well beyond the scope of this discussion, thus I'll leave it at that. If it were simply a matter of working out and eating more calories than maintenance, we'd all all be looking like Arnold Scwartznegger - well, it just doesn't happen that way unfortunately

. For the experienced weightlifter, muscle comes on very slowly - a few pounds a year tops. It doesn't take many additional calories to stimulate muscle growth, but calories - more importantly - protein, needs to be available, and the body needs to be in a anabolic state.
Now for the unfortunate truth: No matter what kind of diet you are on (low fat, low carb, ketogenic, cyclic ketogenic, etc) if you're metabolism remains slow and "out of whack" you will soon be right back to square one. Thus I highly recommend you reep the lasting rewards of an increased metabolism by building all the extra lean muscle you can. This added muscle will be your "insurance policy" so to speak. Don't fall into the trap like millions of dieters do each year, it will be such a waste if you do.
Damn, sorry about the long post, but in my 18 years of training and observation, I've learned many valuable things which I formerly didn't quite grasp the significance. Hope I make sense.