How do I lose fats while still gaining muscle?

17M, 173cm and 74kg.

My final exams are done which means I have 3-4 months period to really work on my body as a start. I have a belly and fats all over my body and I want to lose that while still training to look buff.

I've seen somewhere that you have to be on a calorie deficit while working out. But I want to know more in depth. How do I know what foods I should buy or how am I gonna be doing this the right way? Or maybe I should not start right now as my body is still growing and I should wait out till my body has stopped growing? Can anyone please give me a brief explanation. I would really appreciate it.