The Maryland attorney general said in an opinion yesterday that Prince George's and Montgomery counties must pay off millions of dollars in debts on school buildings the countries have closed in an effort to save money.

The debts could amount to $2.8 million for schools closed in Montogmery and $2.2 million for those closed in Prince George's, according to officials in both countries. As much as $4.7 million more may be at stake for schools Prince George's is considering shutting down this summer.

The state had originally been paying the contruction debts under a law that was designed to equalize the burden of public education among all the taxpayers in the sate. But recently the state declared that the law did not apply to schools that were closed and no longer being used for educational purposes. The counties disputed this claim, and the state sought the attorney general's opinion.

The attorney general's opinion yesterday held that the state's Interagency Committee for School Contruction and the Board of Public Works "may require local jurisdictions to reassume" the construction debts.

"If they're going to withhold $2.8 million (in debts), we'd have to increase taxes to make up for it," said Montgomery Country Budget Director John Short when told of the opinion. The fact that local taxpayers may now be asked to pick up the tab on the school construction debts adds a new twist to the controversy over the school closings. The closings, a result of declining enrollments in recent years, have been fought by community groups, which contest the school official's estimates of how much money the closings save.

The problem over the contruction debts arose when the state's Interagency Committee decided that laws acquiring the state to pay for schools that have been closed and put to other uses.

The state's interagency committee previously has taken a firm position that the local jurisdictions must pick up the debts on closed schools, but yesterday, Leo Ritter, executive director of the committee's staff, said "Ithink we're always open to compromise and discussion."

Both the Montgomery and Prince George's county school boards have, in some cases, transferred the closed schools to their county governments, which in turn lease them or use them for government business.

Col. Eliot Robertson, budget director of the Prince George's schools, pointed out that if the counties sell the buildings or lease them they may realize a high enough return to pay off the debts.

In many places, however, the buildings are difficult to seel or lease because they are in residential areas where businesses or other possible investors cannot move in.

Short, Montgomery's budget director, said that even though the county already is leasing some of the buildings, "We're just trying to break even. We're not making any money."

In some cases, school oficals also have temporarily evaded the committee's orders to pay the debts by granting the county permits to sue the buildings rather than transferring ownership.

Robertson pointed to this fact yesterday, noting that "as long as the buildings are in our ownership, nothing changes."

In Montgomery County, 18 schools have been closed since 1976, and are either being leased or have been transferred to the county government, school officials said. In Prince Geroge's 10 schools have been closed, and the board will consider closing 15 schools with outstanding construction debts at its meeting April 18.

For more Prince George's schools facing possible closing have bo outstanding contruction debts: Andrews Air Force Base, Cheverly-Tuxedo, O.W. Phair and Wildercroft.

On one of them, Kent Junior High School, there is a debtof more than $1 million remainint, the highest construction debt of the 19.