In a long term, there are a few options.
1. Leave A/B alone, you get A's expertise, however you have to spend your time to fix "bad" stuff created by him.
This actually is not bad. You have some work to do that is why you are valuable! :-)
2. Change A's behavior. You will be the mentor of A, and help him to grow to be a better leader in managerial area.
If A is smart enough, you will be replaced or he will find a new position. However if you get promoted, it is worth a try as A will be loyal to you.
3. Change B's behavor to improve his technical skill
Similar to 2
4. Many more options as we are the people. Management is never easy :-)