Independent counsel Lawrence E. Walsh said yesterday that he is determined to pursue the Iran-contra investigation as long as it takes to bring it to a conclusion, even if it lasts up to three years.

"I have no limitations on my commitment," Walsh said in an interview. "I certainly hope that it's not going to take anything like that. But if there are trials, appeals and retrials, it could theoretically take a long time."

The Justice Department on Tuesday launched a slashing attack on the independent counsel system, denouncing it as unconstitutional, complaining that it invited investigations of trivialities and singling out Walsh's inquiry as too expensive.

Walsh, a former high-ranking Justice Department official, seemed unperturbed by the sharp attack, which was delivered by Assistant Attorney General John R. Bolton against a backdrop of previously stated "constitutional concerns" about the 1978 independent counsel law.

The statute, enacted to handle criminal allegations against high-ranking government officials, will expire in January unless Congress renews it. Legislation to make the system permanent is pending on Capitol Hill, but Bolton, who said his remarks had been cleared by the White House counsel's office and the Office of Management and Budget, said his department would recommend a veto.

"These people {independent counsels} are unconstrained and unsupervised by anyone," Bolton charged. He maintained that any law authorizing a prosecutor to investigate federal crimes without being accountable to the president is unconstitutional.

Walsh acknowledged that he has a much freer hand than do regular Justice Department prosecutors, who must report to the attorney general and compete with each other for resources. But Walsh added that he is controlled by the mandate that a three-judge federal court gave him last December when they appointed him to conduct the investigation under the Ethics in Government Act of 1978.

"Let's face it," he said. "You can't have maximum accountability and maximum independence. You have to decide what is most important for the country."

Walsh and others have said that outside investigations of high-level government officials are important to ensure public confidence in the administration of justice; they have pointed out that the appointment of an independent counsel on the Iran-contra matter was recommended last fall by President Reagan and Attorney General Edwin Meese III as necessary to avoid "the potential for conflict of interest."

At the White House yesterday, reaction to Bolton's pronouncement was mixed. Presidential spokesman Marlin Fitzwater initially told reporters that "the existing counsels have received the full support of the president" and that some of the language in Bolton's statement was "intemperate and contentious."

But later in his briefing, Fitzwater said Bolton's letter "speaks for the administration {and} . . . represents our position on the legislation."

Meese, who has since come under criminal investigation by another independent counsel, recused himself from the departmental deliberations leading up to Bolton's attack.

Senior White House and Justice officials, meanwhile, were grumbling about each other's performance in the episode. At the White House, one official said that what most upset them was not Bolton's letter containing the veto threat, but the fuel Bolton added to the fire at a Tuesday afternoon news conference.

"The timing couldn't be worse," this official said. "It was like taking a club and going out there and beating on it."

At the Justice Department, however, officials were smarting over Fitzwater's comments and said that the only wording changes suggested by the White House in Bolton's letter were primarily stylistic and not mandatory.

"OMB even wanted insertion of a sentence that would have made the letter stronger," said one Justice source.

House Judiciary Committee Chairman Peter W. Rodino Jr. (D-N.J.) said he considered the department's position "outrageous."

"Apparently this administration is now unwilling to face the results of careful, unbiased scrutiny by the very independent counsel it has requested," he said. "The independent counsel statute has strong bipartisan support in Congress. And every indication is that it will be reenacted."

Walsh defended the $59,808-a- month rental of his downtown Washington headquarters as a choice made by the General Services Administration in light of three requirements: the size of his staff, desired proximity to the U.S. Courthouse and Federal Bureau of Investigation headquarters, and adequate security for the thousands of classified documents involved in the inquiry.

GSA signed a two-year lease on the suite in the new Columbia Square building with an option to renew for a third year. Walsh said yesterday in response to a question that he was prepared to stay that long if needed, but the length of the lease, he said, did not reflect an estimate on his part of the duration of the inquiry. He said GSA has informed his office that another government tenant could be found if Walsh finishes before the lease's two-year term is up.