There are plenty of reasons to eat better & work out - improving your health, losing weight, and gaining muscle to name a few. Most people have multiple reasons and luckily these tend to go together quite well. But losing weight AND gaining muscle can be a bit more complicated.
You’re already familiar with the various ways of losing weight - specifically creating a calorie deficit - but if you want to gain muscle as well, that can’t be all you do. In fact, gaining lean muscle requires energy and specific nutrients which means you should focus not only on how many calories you’re consuming but also which nutrient-rich foods you eat (as well as exercising regularly!). Without all of these things, you’ll reach a plateau and be unable to go further.