There are many reasons to take advanced classes while in high school: a GPA boost, intellectual stimulation, high school credit, a little sparkle on your college applications. One of the most common reasons, though, is to apply that credit to college as well. First, let's go over the three ways that advanced classes in high school can influence your classes in college.
1) Course equivalency. Some AP courses or dual-enrollment courses are considered equal to college courses, in which case you can receive credit for the corresponding course.
2) Credit. Generally, colleges will have a certain number of credits you need to graduate, and advanced high school classes can sometimes count towards that total.
3) Placement. You might not get college credit for advanced high school classes, but sometimes it can allow you to take a more advanced class from the get-go. For example, if you take AP Spanish, you might not get college credit for it, but you might be able to start at a higher level Spanish class as opposed to starting at an introductory course.
So, how can you find out what will count for what? Unfortunately there is not a master list of what does and doesn't count for every class, because dual-enrollment offerings are different everywhere. However, College Board does have a little known page that lets you check what your AP scores might count for at most colleges. Check it out here.
It's important to note that at top schools, you will likely not be able to get credit for your high school courses. In my personal experience, I attend Brown University and despite taking 16 high level classes before arriving, none of them counted for anything here. I think of this as a good thing, though, because it's a fresh start and allows for unlimited academic exploration.