Background: Sugarcane is the most efficient crop for production of (1G) ethanol. Additionally, sugarcane bagasse can be used to produce (2G) ethanol. However, the manufacture of 2G ethanol in large scale is not a consolidated process yet. Thus, a detailed economic analysis, based on consistent simulations of the process, is worthwhile. Moreover, both ethanol and electric energy markets have been extremely volatile in Brazil, which suggests that a flexible biorefinery, able to switch between 2G ethanol and electric energy production, could be an option to absorb fluctuations in relative prices. Simulations of three cases were run using the software EMSO: production of 1G ethanol + electric energy, of 1G + 2G ethanol and a flexible biorefinery. Bagasse for 2G ethanol was pretreated with a weak acid solution, followed by enzymatic hydrolysis, while 50\% of sugarcane trash (mostly leaves) was used as surplus fuel. Results: With maximum diversion of bagasse to 2G ethanol (74\% of the total), an increase of 25.8\% in ethanol production (reaching 115.2 L/tonne of sugarcane) was achieved. An increase of 21.1\% in the current ethanol price would be enough to make all three biorefineries economically viable (11.5\% for the 1G + 2G dedicated biorefinery). For 2012 prices, the flexible biorefinery presented a lower Internal Rate of Return (IRR) than the 1G + 2G dedicated biorefinery. The impact of electric energy prices (auction and spot market) and of enzyme costs on the IRR was not as significant as it would be expected. Conclusions: For current market prices in Brazil, not even production of 1G bioethanol is economically feasible. However, the 1G + 2G dedicated biorefinery is closer to feasibility than the conventional 1G + electric energy industrial plant. Besides, the IRR of the 1G + 2G biorefinery is more sensitive with respect to the price of ethanol, and an increase of 11.5\% in this value would be enough to achieve feasibility. The ability of the flexible biorefinery to take advantage of seasonal fluctuations does not make up for its higher investment cost, in the present scenario.