Lagrangian density for the electromagnetic field I want to know how the Lagrangian density for the electromagnetic field is written in the following form: 
 A: Arriving at the Lagrangian Density
The Maxwell Lagrangian density in terms of the field-strength tensor $F_{\mu\nu}$ (which has the interpretation of the curvatature of a $U(1)$ connection) is given by,
$$\mathcal{L}=-\frac{1}{4}F_{\mu\nu}F^{\mu\nu} = -\frac{1}{4}\left( \partial_\mu A_\nu-\partial_\nu A_\mu \right)\left( \partial^\mu A^\nu -\partial^\nu A^\mu \right)$$
To arrive at your form of the Lagrangian density, simply use the explicit relation to the $E$ and $B$ fields,
$$F_{\mu\nu} = \left( 
\begin{array}{cccc}
0 && -E_x && -E_y && -E_z \\
-E_x && 0 && -B_z && B_y \\
-E_y && B_z && 0 && -B_x \\
-E_z && -B_y && -B_x && 0
\end{array}
\right)$$
(Note: all expressions are written in terms of natural units.) Arriving at $\mathcal{L}$ itself requires some preliminaries in Lie group theory, and quantum field theory - see Peskin and Schroeder's text for a derivation.

Addressing Lagrangian and Lagrangian density confusion
The Lagrangian density is $\mathcal{L}$, and integrating over all space yields the Lagrangian,
$$L = \int d^dx \, \mathcal{L}$$
The action is given by the integral over time of the Lagrangian, hence,
$$S = \int dt \, L = \int d^d x \, dt \, \mathcal{L}$$
In your case, the top equation is the Lagrangian, and the bottom is the Lagrangian density. In field theory, we only really care about the action $S$ and Lagrangian density $\mathcal{L}$, and so we often call what would be the Lagrangian density as simply the Lagrangian.
