The biggest fear when trying to gain weight and add muscle size is that the process used to reach those goals will also make you fat. It's a real concern. But, you should first realize that it is impossible to only put on muscle. If you have a calorie surplus, which is required for putting on muscle, you will also inevitably put on a little fat.
Don't feel down. Answer this question: Would you mind putting on a little fat for a lot of muscle? Well, that answer to that is the key for fixing your mentality when it comes to gaining weight and fat. It is significantly faster to lose fat than to put on new muscle mass. Of course, your goal should be to maximize muscle gains while minimizing fat gains, but try not to pay too much attention to slight fat gains during any "massbuilding" phase. If you train properly and follow a clean diet, it is possible to add significant amounts of mass without adding too much body fat.
More strength means more muscle. Muscle burns more calories than fat. If you train to build muscle, you'll burn more calories which will eventually make it easier to reach a lower body fat percentage. That's why many trainers advocate focusing on maximizing strength. Keep strength as your primary goal and everything else will fall in place.
Learn your macronutrients. Eating enough to gain weight is one thing. But, eating enough food to gain GOOD weight is another thing. Altering the ratio of protein, fat, and carbohydrates is the most important thing you can alter to maximize your likelihood of reaching any fitness goal. You need to know how much of each macronutrient your body needs for a specific goal. Eating the right ratios of macronutrients when trying to add muscle will limit how many calories get stored as fat.
Eating clean also means exercising discipline even if you are trying to gain weight. Avoid junk food and eating out! Limit your cheat meals to once or twice a week.
Set reasonable and attainable goals. Like I said before, putting on fat is inevitable when you are trying to gain weight. Not all of your gains can be muscle. But, your goal should be to limit fat gains while maximizing muscle gains. If you gain 10 lbs, but only 4 lbs of that are fat, I would call that a resounding success.
Everyone always wants the impossible. Don't let that get you distracted from your ultimate goal. Gaining a little bit of fat in order to gain a lot of muscle is a good trade-off. Once your body fat percentage starts to get higher than you want it, just drop into a 6-8 week cutting cycle to get rid of the excess fat while preserving the muscle you put on. For this time period, you will want to shift to a calorie restricted diet, change your macronutrient ratio and add in some cardio. If you are serious about preserving your muscle gains while losing body fat, I highly suggest using a cyclical ketogenic diet.