There's absolutely no sensible way to "win". What is your victory condition? The whole Afghan territory under uncontested control of an American-supporting elected government? Look at Libya, Syria, Palestine, Algeria, even Egypt, Lebanon, Turkey. Look at Zaire, Zimbabwe, Rwanda. Heck, look at Hungary, Brazil, Poland, even the USA itself. Look at 1920s-1930s Germany!
When things aren't going well, people are going to blame the government. When people are poor, and hungry, and see other people who do manage to get enough because they work for [fill in the blank, but "government" or "robber barons" or "drug cartels" are often here], they're angry and jealous. A Strong Man who will Clean Things Up and Get It Done is an easy, safe solution. Couple that with nationalism/patriotism/chauvinism - such as is always caused by, say, an alien invader coming in to determine which parties or views are "acceptable" and which aren't - and extreme conservative military leaders or groups, most often also strongly religious, will always win.
The Taliban - or the Muslim Brotherhood, or the Afghan Islam Party for Peace and Prosperity, or the Brotherhood of Nod, or whatever they call themselves - will simply win an election after you leave, because of a weak government, corruption, lack of power to affect change, propaganda playing on fear and hunger.
If you bomb enough people to make sure the Good Guys are in the majority -well, congrats, you've just caused a whole new generation to hate you, and they'll definitely vote against you soon enough.
This war, much like most others, can only be won by convincing the population to see you as liberators instead of oppressors. The US army is horrible, horrible, horrible at this (note that I'm not saying any other army is better at it). Russia-style Facebook influencing is more likely to bring peace to the region than simply keeping boots on the ground. You've now got a whole generation of Afghani who were born and grew up in a country continuously ravaged by war and hostile occupation. I'm sure many young Afghani don't particularly like the Taliban and their extremist islamist positions - but what's the alternative?
Imagine a world where the European Union steps in to secure human rights and free speech and such in the USA because the Republican party has gone overboard and has more-or-less installed a theocratic government, and stopped any other party from appearing on the ballot for elections. The EU bombs thousands of Americans, puts soldiers all over, burns the crops, pollutes the water - oh, and for some reason, they all insist on speaking German or French to you instead of English, and they think you should just learn their language, too. After 17 years of that, pretty much all American young people would hate the EU and all it stands for - even if the only real alternative is a Republic where Mike Pence is a soft moderate.