In some cases, the assumption that explanatory variables are not correlated with the residuals cannot be fulfilled and hence least squares method no longer efficient and consistent. However, practically speaking, such a situation is not avoidable. This includes for examples:

Some of the explanatory variables are measured with errors, and thus the measurement errors are absorbed in the residuals.

There are simultaneity problems where some of the variables are endogenously determined

Expectation terms are included in the equation.

Panel data are estimated with pooled least squares.

The regression involves dynamic terms.
The methods of instrumental variables can be used to tackle the above problems. The instruments have to be correlated to the explanatory variables but at the same time uncorrelated to the residuals. This seems very tricky since the higher the correlation to the explanatory variables, the more likely they are correlated to the residuals. But some how you have to find instruments that meet the criteria.
The twostage least squares (2SLS) is a special case of instrumental variable methods and the IV estimate can be obtained by employing the 2SLS procedure. In the 2SLS procedure, there are two least squares involved. The first stage involves regressing all explanatory variables on all instruments and then get the fitted values. In the second stage, the fitted values are used to replace the original explanatory variables. For technical detail you may consult to the following references:
Green, W.H (2003), Econometric Analysis (5th edition). Prentice Hall.
Johnston, J and DiNardo, J (1997). Econometric Methods (4th edition). McGrawHill.
Judge, G.G., Griffiths, W.E., Hill, R.C., Lutkepohl, H., Lee, T.C. (1985). The Theory and Practice of Econometrics (2nd edition). John Wiley and Sons.
Heij, C et.al (2004), Econometric Methods with Applications in Business and Economics. Oxford University Press.
IV/2SLS estimation
It should be clear at the outset that there are some terminology used in iRegand and there may be slight variations amongst regression software. Explanatory variables consist both endogenous and exogenous variables. The number of instrument must be at least as many as the number of explanatory variables. All exogenous variables, notably the constant term, must be included in the instrument list. Hence you have to find the appropriate instruments for endogenous variables.
You can run IV/2SLS in iRegand as simple as:
Step 1. Tap on estimation button and select Instrumental Variables Least Squares
Step 2. Define a dependent variable, explanatory variables, and instruments.
Step 3. Run and see the results.
It should be noted that the estimated coefficients are from the second stage regression and that coefficients are applied to the original explanatory variables for estimating the residuals. Hence the R2R2 can be negative. As comparison, the second stage R2 R2 is also displayed. Large difference between the two R2R2 should indicate that the choice of instruments is problematic.
Diagnostic tests
Various diagnostic tests can be done right after W2SLS estimation. You have to be aware that each test is carried out somewhat differently from the same test within OLS, WLS, or 2SLS. Notice the header of the test results to get a sense of what is the apps doing for you. The Arch test is taken as an example:
Step 1. Tap on the auxiliary menu, select the Arch test.