without getting into semantics like the lifting thread, basically; calorie in vs calorie out. Find your maintenance calorie level to maintain your current shape. 500 calorie surplus = weight gain. 500 calorie deficit = weight loss. Calories = total energy consumed. Fats and carbs = insulin = energy. The way energy is absorbed is different between carbs and fats. Protein = muscle repair. Im sure someone will likely correct me if im wrong, but this is the basic ins and outs and follows IIFYM (if it fits your macros). Calorie in vs calorie out will adjust your body fat % macros will help adjust your bodies composition.
To work out your current macro and caloric level, go to
myfitnesspal and register. Fill in your details, and don't worry so much about the goals, but use it for the food tracking. Type in foods you buy from shops, search by brands etc. and put in your serving size and it will give you the macro/caloric value.
Look up a guy called Nick Cheadle, and/or Aaron Curtis, who makes this info basic. Yup, they're physique/natural bodybuilders but following their (and other accurate nutrition advice) is essential to any weight loss/muscle gain program.