We consider second order elliptic differential operators on a bounded Lipschitz domain Ω. Firstly, we establish a natural one-to-one correspondence between their self-adjoint extensions, with domains of definition containing in H1(Ω), and Lagrangian planes in H1/2(∂Ω)×H−1/2(∂Ω). Secondly, we derive a formula relating the spectral flow of the one-parameter families of such operators to the Maslov index, the topological invariant counting the signed number of conjugate points of paths of Lagrangian planes in H1/2(∂Ω)×H−1/2(∂Ω). Furthermore, we compute the Morse index, the number of negative eigenvalues, in terms of the Maslov index for several classes of the second order operators: the θ→-periodic Schrödinger operators on a period cell Q⊂Rn, the elliptic operators with Robin-type boundary conditions, and the abstract self-adjoint extensions of the Schrödinger operators on star-shaped domains. Our work is built on the techniques recently developed by B. Booß-Bavnbek, K. Furutani, and C. Zhu, and extends the scope of validity of their spectral flow formula by incorporating the self-adjoint extensions of the second order operators with domains in the first order Sobolev space H1(Ω). In addition, we generalize the results concerning relations between the Maslov and Morse indices quite recently obtained by G. Cox, J. Deng, C. Jones, J. Marzuola, A. Sukhtayev and the authors. Finally, we describe and study a link between the theory of abstract boundary triples and the Lagrangian description of self-adjoint extensions of abstract symmetric operators.