Consumer electronics retailer Best Buy (NYSE:BBY) is now about two years into the turnaround effort initiated by CEO Hubert Joly, and all of the pieces are starting to fall into place. The third quarter was a strong one for the company, with a 3.2% increase in domestic comparable-store sales despite the decline in the consumer electronics industry as a whole, and earnings handily beating analyst estimates.

While Best Buy will certainly face some challenges going forward, particularly regarding online sales, which are becoming an increasing percentage of the company's business, the progress made so far has transformed the retailer from a dinosaur that many thought was doomed into a nimble, omnichannel force to be reckoned with. Amazon (NASDAQ:AMZN) may still be the king of online retail, but Best Buy is catching up.

How Best Buy righted the ship
Best Buy's strategy over the last two years can be summed up in three points. First, lowering prices in order to be more competitive with online retailers. Second, slashing those costs without negatively affecting the customer experience. And third, growing online sales and becoming a true omnichannel retailer.

Lowering prices, along with implementing a price matching policy, has kept Best Buy competitive, but gross margins have suffered. During the third quarter, gross margin fell to 22.7%, down from 23.1% during the third quarter of 2013 and 23.8% during the third quarter of 2012. This may not seem like much, but for a company that sells around $42 billion worth of products annually, each percentage point of gross margin represents about $420 million in gross profit.

In order to make up for the declining gross margin, Best Buy has aggressively cut costs. As part of the company's Renew Blue initiative, Best Buy has removed a cumulative $965 million in annualized costs since the turnaround began. All of these cost cuts didn't fall through to the bottom line, since Best Buy also invested in areas like e-commerce, but it has more than made up for the falling gross margin. During the third quarter, SG&A expenses as a percentage of revenue fell to 20.6%, down from 21.8% during the third quarter of 2013, and 23.4% during the third quarter of 2012.

It's important to understand that much of these cost cuts were the result of improving the supply chain and removing layers of management. In fact, early in the company's turnaround, Best Buy invested in increased training for its staff. Had the company slashed costs at the store level, it could have hurt the customer experience, ruining any chances of a successful turnaround.

One area of heavy investment for the company has been the e-commerce channel, and so far, it's paid off. Online sales have been accelerating, rising by 21.6% during the third quarter, up from a 15.1% increase during the third quarter of 2013 and a 10.3% increase during the third quarter of 2012. Online revenue is still a relatively small part of Best Buy's business, just 6.4% of total sales during the third quarter, but continued 20%-plus annual growth will cause that percentage to rise quickly over the next few years.

Best Buy's recent online success is due mostly to its ship-from-store initiative, where each store acts as a mini-distribution center, able to fulfill online orders. This opens up the merchandise of every Best Buy store to the website, greatly increasing the available inventory online while also reducing shipping times.

One area where Best Buy still has the ability to remove substantial costs is returned, damaged, and clearance items, and ship-from-store is the solution to this problem. Previously, when an item was returned to a store, that item was essentially stuck in that store, meaning that a big markdown was often necessary to get rid of it. With ship-from-store, returned, clearance, and refurbished items in all of Best Buy's stores can be made available online, greatly expanding the pool of potential buyers and, if everything goes to plan, leading to a substantially smaller markdown. This should help boost the gross margin, partially counteracting the effects from Best Buy's lower prices. 

Challenges ahead
This is the story so far. Best Buy has become more competitive, more efficient, and has leveraged its store base to grow online sales in a way that can't be matched by online-only retailers. The third quarter saw the best comparable-store sales performance from the company in years, and earnings are rising. In the third quarter, non-GAAP EPS was $0.32, up from just $0.18 during the third quarter of 2013.

Best Buy still faces challenges, of course, and the biggest one is, unsurprisingly, Amazon. Best Buy's online sales are a pittance compared to those of Amazon, and with the online retail giant constantly expanding its distribution center footprint and making its operations more efficient, Best Buy needs to continue to cut costs wherever it can. With Amazon perfectly content with sacrificing margins in order to win market share, Best Buy is facing the worst kind of competitor.

Best Buy's most effective weapon against Amazon is, ironically, its stores. Best Buy is the only nationwide consumer electronics retailer left standing, and it has become the default option for many consumers. And with each store acting as a mini-distribution center, Best Buy has a distinct advantage over Amazon's far smaller footprint. Amazon may be more efficient, but Best Buy has been able to use existing assets to vastly improve its online channel.

All of the pieces of Best Buy's turnaround are in place, and the results so far have been very positive. Whether Best Buy can maintain the sales growth that it managed during the third quarter is an open question, but the company is far more efficient today than it was two years ago. While Amazon has some important advantages, it's not invincible, and Best Buy has the opportunity to steal away some online market share in the coming years. Best Buy's turnaround appears to be gaining momentum, and this holiday season will be an important test of whether the company can keep that momentum going.

Timothy Green owns shares of Best Buy. The Motley Fool recommends Amazon.com. The Motley Fool owns shares of Amazon.com. Try any of our Foolish newsletter services free for 30 days. We Fools may not all hold the same opinions, but we all believe that considering a diverse range of insights makes us better investors. The Motley Fool has a disclosure policy.