PRAGUE, Aug 23 (Reuters) - The Czech government has agreed to buy the main Czech gas storage company RWE Gas Storage CZ from Germany's RWE to bolster energy security after Russia's invasion of Ukraine, Prime Minister Petr Fiala said on Wednesday.

The underground storage's capacity of 2.7 billion cubic metres represents more than three quarters of the country's gas storage capacity, enough to supply the Czech Republic with gas for about two months during winter time.

RWE initially put the assets up for sale last year but scrapped the deal after receiving just one bid. The government has been considering purchasing the storage since then.

"We can't just rely on others, we have to do something ourselves. My government is taking a number of active steps to ensure the energy security of the CR," Fiala told a news conference.

The six storage tanks have the capacity of about a third of the annual gas consumption, he said.

Fiala said that the price of the storage capacity purchased would be revealed on Thursday after both parties sign the contract.

The purchase will be done through the government-controlled electricity transmission grid operator CEPS, Fiala said.

Under the plan to increase control over energy infrastructure, the government is also planning to restructure the 70% state-owned electricity producer CEZ and media reports have said it was also interested in taking over gas transmission operator NET4GAS. Fiala declined to comment on NET4GAS on Wednesday. (Reporting by Jan Lopatka and Robert Muller; editing by David Evans)