The laws of thermodynamics can be stated in several different and equivalent ways. Here is an example of a statement of the First Law of Thermodynamics:
A physical statement of the first law of thermodynamics is that the change of energy in a system is independent of the path taken.
This is a very abstract definition that is not very useful for our purposes. We will be using a less formal statement. That is:
The total Internal Energy of an Isolated System is a constant.
In other words, the amount of heat, work, nuclear, kinetic, or any other form of energy can change. However, the sum of all forms of energy present in an isolated system must add to the same value.
Analysis using this law is still useful if you are not considering an isolated system. If you are performing an energy flow analysis in a close system, you need to constrain the energy inputs and outputs (from/to) the system's surrounding. The difference between these energy inputs and outputs will give you an approximate value to the internal energy of your closed systems.
Just for the Math of it:
For an overview of the mathematical treatment of the laws of thermodynamics, you can visit the Wikipedia paged linked. There are many different references for in-depth treatment of thermodynamics. Two books that I have used in the past are:
For a book that focuses on concepts: Anderson, G. M. Thermodynamics of Natural Systems. Cambridge University Press; 2 edition (August 20, 2009).
For a more mathematical book: Kittel C. and Kroemer M. Thermal Physics. W. H. Freeman; Second Edition edition (January 15, 1980).