Hi Chengshu,
Sorry about the slow reply.
The overlap(psi,H,psi) method is intended for finite, open boundary MPS and finite, open boundary MPOs.
To get the energy from infinite DMRG, one way is to get the energy from the result object:
auto res = idmrg(...);
Print(res.energy);
To actually evaluate the energy from an MPO takes more explanation and it's hard to type it all out here. But basically the kind of MPOs that idmrg expects have left and right boundary vectors stored in H.A(0) and H.A(N+1) (where N = H.N() is the number of sites of the MPO).
The MPS returned from idmrg (meaning the value of psi which is passed by reference after idmrg returns) is in a right-orthogonal gauge, meaning all of it's tensors obey the right orthogonality condition. The tensor psi.A(0) contains the "center matrix" of the MPS, so to construct part of the infinite wavefunction you must multiply psi.A(0)* psi.A(1) to get the orthogonality center tensor on site 1. See the sample/idmrg.cc sample code to see an example of this. Then one can extend the MPS by continuing to multiply by psi.A(2), psi.A(3), ..., psi.(N), psi.A(1), psi.A(2), etc for as many unit cells as needed e.g. to compute correlation functions and or matrix elements of part of the Hamiltonian or an MPO.
Finally, in the result object the idmrg algorithm returns, there are two tensors res.HL and res.HR which are the left and right "Hamiltonian environment" tensors computed as the idmrg algorithm grows the system longer and longer. These are the MPO projected into the semi-infinite "wings" or left and right basis of the infinite MPS. You can use these together with one unit cell of the MPO and MPS to compute the same energy that idmrg reports.
At some point I plan to write a detailed documentation with figures about the idmrg algorithm in ITensor. There is a draft of one written by a couple students but it may have some inaccuracies. It is a fairly complex algorithm to explain, but it follows pretty closely to the algorithm as explained by Schollwock in his review article. I hope what I wrote above gives you the information you need. Also I'd encourage you to read through the idmrg code itself and draw diagrams and/or take notes on how it works for yourself and you can learn a lot this way about its inner workings and the algorithm.
Miles