Stocks extended gains on Wednesday as the energy sector rallied on a better-than-expected read on crude inventories.

The S&P 500 was up 0.67%, the Dow Jones Industrial Average added 0.62%, and the Nasdaq gained 0.6%. 

Crude inventories rose by 3.4 million barrels over the past week, according to the Energy Information Administration, in-line with analysts' expectations. Distillate inventories, which include diesel, fell by 3 million barrels, a faster pace than an expected 1.7 million-barrel decline. West Texas Intermediate crude oil gained 3.2% to $44.56 a barrel. 

The energy sector rebounded on the data following two straight days of declines. Among the best performers, Exxon Mobil(XOM) - Get Report , Chevron(CVX) - Get Report , Royal Dutch Shell (RDS.A) , BP(BP) - Get Report   and Schlumberger(SLB) - Get Report  rose, while the Energy Select Sector SPDR ETF (XLE) - Get Report added 2.6%. 

Eyes were also on the Federal Reserve which will release a statement Wednesday afternoon following the conclusion of its two-day meeting. While the central bank isn't expected to raise interest rates at the October meeting, investors will be keen to see whether the Fed gives any indication as to whether a December rate hike is in play. 

"The trajectory of recent U.S. data further complicates the Fed's liftoff timing, as does the Committee's desire to simply get off the zero-bound," wrote CRT Capital's Ian Lyngen in a note. "It promises to be an interesting, if prolonged, process." 

AIG(AIG) - Get Report shares climbed 3% after activist investor Carl Icahn disclosed a stake in the company and called for a breakup of its assets. In an open letter to CEO Peter Hancock, Icahn said the insurance company was "too big to succeed" and faces increasing regulatory pressure due to its size. 

In earnings news, Apple(AAPL) - Get Report climbed 1.9% after iPhone sales in China boosted overall quarterly revenue. The tech giant earned $1.96 a share in its recent quarter, above estimates of $1.88. Revenue jumped 22% to $51.5 billion and beat forecasts. The company sold 48.04 million iPhones during the quarter, only two days of which included sales of the new iPhone 6S and 6S Plus.

Twitter(TWTR) - Get Report slumped 10% after releasing a disappointing sales outlook and slowing user growth. The social network expects fourth-quarter revenue in the range of $695 million to $710 million. Analysts had expected an average $741 million. Over the third quarter, the company reported 320 million average monthly active users, up 11% from a year earlier, but 4 million short estimates. 

Anthem(ANTM) - Get Report shares were more than 6% lower despite a better-than-expected quarter. The health insurance company earned an adjusted $2.73 a share over its third quarter, 40 cents above estimates. Results were boosted by an increase in medical enrollment, particularly in its commercial and government segments. 

Hershey(HSY) - Get Report dropped 4% after a 31% decline in third-quarter earnings. The chocolate company was hit by higher restructuring costs over the quarter as it reduces costs to combat weaker demand and increasing costs for cocoa.

Gilead Sciences(GILD) - Get Report fell 2.6% after quarterly sales of its key hepatitis C treatments came in flat year over year as health insurers opted for less expensive medicine. However, the drugmaker did top revenue and earnings estimates over the quarter. 

Walgreens Boots Alliance(WBA) - Get Report moved higher after agreeing to acquire rival Rite Aid(RAD) - Get Report for $9.4 billion, or $9 a share. The all-cash deal combines the second- and third-largest drugstore chains in the U.S.

Separately, Walgreens reported a better-than-expected quarter, boosted by the inclusion of Alliance Boots sales after its acquisition closed. Net income of 88 cents beat estimates by 7 cents, while revenue of $28.52 billion topped forecasts by $70 million.

Starwood Hotels (HOT) spiked 9% on reports Hyatt Hotels(H) - Get Report is in advanced talks to purchase the hotel chain. Sources said an agreement could be reached in as little as a week, according to CNBC. Hyatt shares added 5%.