NStar is teaming up with A123 Systems to test the advanced battery maker’s large-scale energy-storage device, a technology that could be key to integrating intermittent energy from wind turbines and solar arrays into the nation’s power grids.

Company officials say they plan to install one of A123’s storage devices at an NStar substation in Medway, where it will be connected to the grid and used to capture electricity when supply exceeds demand and to release it when more power is needed. The giant battery system - a collection of 82,000 to 84,000 lithium-ion battery cells housed in a 53-foot-long shipping container - is expected to be up and running by the middle of next year.

Lawrence Gelbien, NStar’s vice president of engineering, said the Boston utility is interested in how A123’s technology can be used to regulate the power flowing through the grid.

Right now, Gelbien said, electricity on the grid is not stored and must be used as it is generated. That poses a problem with renewable energy sources, like wind turbines, which generate power only when the wind is blowing, and not necessarily when consumers need it. If that power is not used immediately, it is essentially lost.

That’s where the battery system from Waltham-based A123 comes in.

“What we’re really looking at is what benefit can it have to the grid?’’ Gelbien said. “Is a battery storage device a tool that the utility can use to make the intermittent supply of renewables like solar and wind more of a consistent supply of power that’s not affected as much by cloud cover and loss of wind?’’

NStar and the other three investor-owned Massachusetts utility companies must address such questions because state regulations require them to obtain 15 percent of their power supply from renewable sources by 2020.

Robert Johnson, vice president of the energy solutions group at A123, said the battery company expects the use of its storage system in Medway to provide “some real life experience and better understanding’’ of the technology. A123 will still own and operate the system once it is installed.

“For us, it’s learning the permitting process and things we can do with our product to make that process easier,’’ Johnson said. “We’ll learn, as a user, how to make a better product for our users.’’

Several A123 clients around the world are using the battery system commercially, but having the technology near the company’s headquarters will be beneficial, Johnson said, especially if potential customers want to try the technology before purchasing.

A number of utilities around the country are testing various energy-storage technologies, but it is too early to tell which will be the most cost-effective and efficient, said Theodore O’Neill, an analyst at Wunderlich Securities in New York. While A123’s advanced battery system is impressive, O’Neill said, its $2 million installed cost is too expensive.

“At some point, this may make sense if they can get the cost of the batteries down enough,’’ O’Neill said. “It’s too early to move the needle, but it is something the utilities probably have to take a look at until they find something that’s cheap enough.’’

Cost is definitely one of the biggest barriers for energy-storage devices, said David Leeds, director of smart grid research at Greentech Media, a Boston research firm. Leeds said the technology - which he called the “missing piece’’ to enabling widespread use of renewable energy sources - would benefit from an investment tax credit currently being considered by Congress.

“The lack of cheap energy storage is what is continuing the natural gas and coal paradigm,’’ he said.

“It is the most important piece of our energy future - in concert with technologies that make the grid more efficient, optimized, and intelligent.’’