Immersed boundary method (IBM) based CFD code has helped considerably in avoiding the tedious grid generation process in fluid flows involving complex geometries. In this work, we have developed an IBM framework to simulate flow, convective heat transfer as-well-as conjugate heat transfer through a highly complex random porous structure. In this framework, we can incorporate any complex solid body as a triangulated surface mesh and an accurate algorithm is proposed to identify solid cells and fluid cells. Moreover, a detailed implementation of periodic boundary condition for velocity and temperature is presented. Detailed code verification process is performed to demonstrate that the method is second-order accurate for both the velocity and temperature fields for all the boundary conditions considered. The developed scheme is shown to be applicable for convective and conjugate heat transfer through highly complex computer-generated realistic open-cell solid foams in a periodic Cartesian domain.