In order to gain muscle in general, you need all types of nutrients to help the body repair the damage you've made while working out, as well as being able to fuel you for your next workout. The cycle is constantly repeating, but in order to make your time in the gym just as worth it when you're eating, you have to know WHAT to eat. I would recommend a diet high in lean fats like nuts, avocadoes, and peanut butter. Keep a moderated carb intake, things like bread, pasta, and keep a high amount of protein intake, along with the everyday vegetables. Vegetables have a lot more protein than you'd think, so I would reccomend specifically spinach. You will slowly start to see your muscle increase over time. Don't over eat because it'll mess with your digestion, but definetely keep a high appetite when you want to gain muscle working out.
In order to lose weight, there are many different ways people have methods to lose weight. One of the more common ideaologies is to hit high amounts of cardio, either everyday or every other day in order to burn whatever calories you've had for the day and more. Cardio is an amazing form of weight loss, but it isn't the only effective way to attain your goal. Steer clear of heavy amounts of cheese, carbs, and things high in dairy and grains only because carbs can turn into fat overtime if consumed in an unbalanced way. Fasting is a very effective way of losing weight. People have a time period throughout the day where they can't eat, only water. Once the period is over, you can break your fast and eat, but only during your window, however long you choose to make it.
Now to maintain weight, this can be tricky. You want to keep your eating habits consistent, first and foremost. People have "cheat days" where they choose to eat whatever it is they want and however much of it they want, but tread lightly because not all people can afford to have a "cheat day". Find out what kind of bodytype you have with an online quiz or an app. There are multiple resources that can help tell you your body type and have an idea of where you stand between your eating and the metabolic ratio of your body. Pay attention to things that happen when you eat, whether you gain weight quickly or slowly, the body is a very sophisticated mechanism, so you must be aware of it. Try to keep your eating habits the same, but switch around foods, so you don't feel bored with the things you eat. Never forget to enjoy your food!