The significance of flow optimization utilizing the lattice Boltzmann (LB) method becomes obvious regarding its advantages as a novel flow field solution method compared to the other conventional computational fluid dynamics techniques. These unique characteristics of the LB method form the main idea of its application to optimization problems. In this research, for the first time, both continuous and discrete adjoint equations were extracted based on the LB method using a general procedure with low implementation cost. The proposed approach could be performed similarly for any optimization problem with the corresponding cost function and design variables vector. Moreover, this approach was not limited to flow fields and could be employed for steady as well as unsteady flows. Initially, the continuous and discrete adjoint LB equations and the cost function gradient vector were derived mathematically in detail using the continuous and discrete LB equations in space and time, respectively. Meanwhile, new adjoint concepts in lattice space were introduced. Finally, the analytical evaluation of the adjoint distribution functions and the cost function gradients was carried out.