People usually say that if you eat less calories than you spend, than you'll lose mass (and this is not my objective, since I want to gain muscle, but lose fats), and if you eat more than you spend, you gain mass (and this is my current objective, but I only want to gain muscle mass, and lose fats). How much should I eat to gain muscle and lose fats? ( Considering that I work out for 1 hour about 4 times a week)
If you go into caloric deficit, you'll lose far more fat than you'll lose muscle. Any type of maintenance workouts will help you retain muscle mass. The only issue you'll have is that the caloric deficit might make you more exhausted, and not lift as heavy as you would during a bulk, for instance.
I've read MacUserT's answer (now deleted), and I somewhat disagree with the notion that you should be focusing too much on your protein intake. If you eat too much protein, the body will simply convert the surplus to fat during a process called gluconeogenesis.
Since we don't know your build, we can't give any detailed advice, but in general, you should be able to make all the changes you want, just by keeping track of what you eat, and how it affects your weight. You'll soon find that you can make small adjustments and see the changes on the scale after a few weeks.
Every one is different, so you're gonna have to find what works for you through trial and error.