In order to achieve your goals, you will have to come up with an exercise/diet routine that will promote muscle growth and limit fat storage. Your workout program should include weight training. You should also be eating a surplus of calories. Figure out how many calories you burn in a day and eat more than that every day. Your body needs a surplus to put on muscle. Getting plenty of protein will also help with the process. I would recommend a protein shake before and after your workout. When gaining weight, there is no way to guarantee that you won't put on more fat. You most likely will. Here's how you deal with it. Once you reach your goal weight, keep gaining until you are a few pounds over your ideal weight. Then change your workout and diet routine to one that will burn fat. Lose that extra weight in the form of fat, and you'll be at your ideal weight with less fat. Now, losing fat and maintaining muscle is also tricky. You still need plenty of protein before and after your workouts so your muscles don't break down too much.
Making any changes to your body takes a very specific plan. But the most basic point is: to gain weight, eat more calories than you burn, and to lose weight eat fewer calories than you burn. In order to maintain control over what type of weight is gained/lost you must focus on meal timing, amount of protein and most importantly, you must watch how your body responds. If you are gaining too much fat, slow down the weight gain by eating fewer calories. If you pay attention to how your body responds, you will find a routine that works for you.