The Senate voted last night to give homeowners a tax break of up to $400 to offset the cost of storm windows, insulation and other steps designed to conserve energy.

The tax credits, if accepted by the House and signed by President Carter, would retroactively apply to projects begun after April 20, 1977, the day Carter sent his energy package to Congress.

Yesterday's vote was the second time in two years the Senate has voted to give tax credits to homeowners for trying to save energy.

Last year, the credits were approved as part of an omnibus energy tax bill that has been tied up in a conference with the House for more than a year.

The administration and the leadership of both chambers have sought to keep the box breaks in the overall energy package to make it easier to sell less popular measures such as those that would raise the cost of heating oil and natural gas. Yesterday's action was an attempt to speed enactment of the homeowners' tax breaks and let the other measures rise or fall on their own.

Yesterday's vote came as something of a surprise in an amendment by Sen. Gary W. Hart (D-Colo.) to a minor tax bill to cut the amount of tax private nonprofit foundations must pay on their investment income. The foundation bill has already been approved by the House.

The Hart amendment also would give homeowners tax credits up to $2,200 for installation of solar heating devices.

The Senate approved the whole measure by voice vote.

Energy Department officials said last night that while they approve of the substance of the Senate vote, the White House still opposes splitting the energy package into popular and unpopular parts.

Sen. Russell B. Long (D.-La.), chairman of the Senate Finance Committee, said that while he, too, agrees with the substance of the Hart amendment, the House will not approve it in conference until House conferees are convinced they cannot get a special tax on domestic crude oil that would raise its price to world levels.

Sources close to the House Ways and Means Committee said that its chairman, Al Ullman (D-Ore.) still wants to keep all energy taxes in one package.

When the bill the Senate passed yesterday goes to conference with the House. Ullman would be unlikely to appoint conferees "who do not share his view," one source said. However, more than 100 members of the House have cosponsored legislation similar to Hart's.Furthermore, in confrontations with Long, Ullman has often been unsuccessful in pushing the House's position.

Sen. Mike Gravel (D-Alaska), upset that his bill to cut foundation taxes was being encumbered with the Hart amendment and several minor ones, tried to attach special tax breaks for producers of energy to the bill as well.

The producer tax breaks are also part of the omnibus energy bill that is languishing in conference. But the Senate defeated Gravel's amendment, 54 to 42.

The bill the Senate passed yesterday would give homeowners a tax credit of 20 percent, up to $400, for home energy conservation devices. For solar energy, the credit would be for the first $2,000 and 20 percent on the next $8,000, up to a maximum of $2,200.

A tax credit is subtracted directly from taxes owed. Thus, if a homeowner brought $1,000 in storm windows, he or she would receive a $200 tax credit. If the tax bill were $2,000, he or she would pay the government $1,800.

Sen. Thomas J. McIntyre (D-N.H.) said that the tax credits, which the public has expected since the president delivered his energy message a year ago April, have been "held hostage" too long to an energy bill that may never emerge from conference. He said the solar energy industry has been left out on a financial limb because of the uncertain status of the credits.

Sen. Charles H. Percy (R-Ill.) said that because the government wants to encourage solar energy as an alternative to fossil fuels, it is time to separate the tax credits from the rest of the energy package.