Generalized definitions of Lagrangian and Hamiltonian functions When we enter into the scope of Analytical mechanics we usually start with these two primary notions: Lagrangian function & Hamiltonian function
And usually textbooks define Lagrangian as $L=T-V$ and Hamiltonian as $H=T+V$ where $T$ is Kinetic energy and $V$ is Potential energy. But as we proceed it turns out Lagrangian and Hamiltonian may not always have these values and this occurs in just some special cases and there is a more general definition.
My question is:


*

*What is the generalized definitions of these two functions? 

*Is there a general defining equation where the mentioned values could be extracted as a special case?
EDIT: A third question
Do we know about the notions of "Kinetic energy" and "Potential energy" beforehand or are they defined after the Lagrangian gets its famous form $L=T-V$ and then we assign $T$ and $V$ their respective definitions?
EDIT 2: A fourth question
What if there were non-conservative fields? Then obviously $V$ term couldn't show their effects(since Potentials are always associated with conservative fields). Then how could we bring the effects of non-conservative fields into play?
 A: *

*This is a huge topic. How general do you want to be? We will only be schematic here. Perhaps the most general setting is a physical system with a set of equations of motion. (The word equations of motion refer to a coupled set of differential equations that governs time evolution. E.g. in Newtonian mechanics, it's Newton's 2nd law.) 

*There are no general algorithms to determine whether a variational formulation exists or not, cf. e.g. this Phys.SE post. In other words, finding a variational formulation is in general an art. 

*Generically, there does not exist a variational formulation for dissipative and non-conservative systems. However, see e.g. this and this Phys.SE posts. For a discussion of the non-conservative forces, see also this Phys.SE post.

*The Lagrangian $L$ need not be of the form $T-U$, cf. e.g. this Phys.SE post. Of course, classes of physical systems do obey $L=T-U$, cf. e.g. this Phys.SE post.

*Next assume that a Lagrangian $L$ is given. To find the Hamiltonian $H$, perform a (possibly singular) Legendre transformation between the generalized velocity and momentum variables. (If the Lagrangian depends on higher time derivatives, cf. e.g. this Phys.SE post, see the Ostrogradsky formalism.)

*For the condition when the Hamiltonian $H$ & the total energy $E$ agree, see e.g. this & this Phys.SE posts & links therein.

*For books on Lagrangian & Hamiltonian formulations, see e.g. this & this resource recommendation lists & links therein.
A: In general - No there is not. In the corresponding formalism, the Lagrange or the Hamilton-function will be the starting point to describe the system, and that means that you have to shape the Lagrange function in a suitable way to describe the system. There are no other properties of the system at that point, that have allready been translated into a mathematical object (Like the kinetic Energy, or the Potential energy), you start with the Lagrange function, and in a suitable system you can afterwards identify terms within the Lagrange-function with $V$ or with $T$. 
However, choosing a Lagrange-function is not entirely abitrary: Your Lagrange function $L(\vec{x}, \dot{\vec{x}})$ is supposed to describe your system. That means for example, that $L$ has the same symmetries as you observe at your system.
For example, consider the free space: Every region is the same to a flying particle, the laws of physics are the same everywhere. That means your have translational invariance, and hence $L(\vec{x} + \vec{p}, \dot{\vec{x}})=L(\vec{x}, \dot{\vec{x}}) $, for every $\vec{p}$ you can think of. That means $L$ doesn't depend on x. Do the same with Rotational invariance, then you know L can just depend on $|\dot{\vec{x}}|$. 
By now L has the form 
$$ 
L= c f(|\dot{\vec{x}}|)
$$
If you demand that every inertial frame of reference will yield the same equations of motion (galileian invariance), then you demand that $$L(\dot{\vec{x}}) = L(\dot{\vec{x}}+\vec{v}) + D(\dot{\vec{x}}) \\
D(\vec{x},\dot{\vec{x}}) = \nabla g(x)\dot{\vec{x}}$$
This is a less rigid condition, the Term $D$ is a gauge-term and doesn't change the equations of motion. One way to satisfy this condition is to choose:
$$ 
L= c \dot{\vec{x}^2}
$$
Then 
$$
L(\dot{\vec{x}}+\vec{v}) = c \dot{\vec{x}^2} + c \vec{v}^2 + 2 c \vec{v} \dot{\vec{x}} = \tilde{L}(\dot{\vec{x}})
$$
$L$ and $\tilde{L}$ will lead to the same equations of motion in two different frames of reference (as you demanded it). L is now shaped in a way that regards homogenity of time, of space, isotropy of space, and free choice of your frame of reference to be symmetries of the system. Now look at the outcome:$$ 
L= c \dot{\vec{x}^2}
$$ 
Up to constants (which will come in to play when you define units), you have the kinetic Energy, and you know this function to correctly describe the motion of a free particle. But you did't know in the first place, that there is something like newtons axioms, or something like energy. Everything you knew where the symmetries, and using them, you arrived at this point. In the same way you can demand gauge invariance, then you will arrive at the electromagnetic coupling terms in the Lagrange-function, and so on. 
