What is Music Theory?
Music theory is basically the study of how music works. It examines the math, and even the science, to try to predict what will sound good. The theory has mostly been developed through analysis of past works by composers in the classical music realm. There are certain relationships between notes and chords that are going to have a good sonority and there are certain notes that will clash.
How is it used
Theory is often used during composition or improvisation. Through solid theory and practice, a composer will be able to tell if the idea they have is going to work or not. It is not an exact science. There will be things that will defy the rules and sound better than you thought they was going to. It is important to know that it is much easier to break the rules and sound good if you know what the rules are in the first place.
Theory is great for improvising in the same way that it is good for composers. After all, improvising is just sped up composing that is performed in real time. You simply cannot be a good improvising soloist without having a firm grasp of the math behind what you are doing.
How is it learned?
If you are a serious musician that is attending college for music, you will have to take at least 2 years of the subject in order to graduate. Most schools require 3 years of theory. It is rigorous but rewarding.
Beginners can also teach themselves. There are a lot of websites with basic information about music theory and how it works. You can also buy a music theory workbook from a company like CR Carole Music. These books are great because they are specifically designed to give players a step by step process of understanding music theory better.
You may think that how well you play your instrument is the only important thing about being a musician. It is important. Having a firm grasp of at least some music theory will help you even further with your instrument and music beyond it.