For the text of the annotation, you can use the decorations.text tikz library.
For stylizing, you can add any options you need in the \draw command, here is an example:
\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0,xmax=5
]
\addplot[mark=none,blue] {x^2};
\draw[red, dashed] (2, \pgfkeysvalueof{/pgfplots/ymin}) -- (2, \pgfkeysvalueof{/pgfplots/ymax});
\draw[green, thick, dotted] (4, \pgfkeysvalueof{/pgfplots/ymin}) -- (4, \pgfkeysvalueof{/pgfplots/ymax});
\draw[blue, very thick, {Stealth}-{Stealth}, postaction={decoration={raise=3pt, text along path, text={some text},text align=center}, decorate}] (2,5) -- (4,5);
\end{axis}
\end{tikzpicture}
\end{document}

Edit:
As required by the OP, I've created the style \myline for the vertical lines (and also a \myarrow one for the arrow of the interval).
Moreover, I exaggerated with the tikz mania. As Torbjørn T. correctly pointed out, using a text along path is overkill for a straight line. You can just put a node above the path, with no need of the decorations.text library.
\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{arrows.meta}
\tikzset{%
myline/.style = {green, very thick, dashed},
myarrow/.style = {blue, very thick, {Stealth}-{Stealth}},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0,xmax=5
]
\addplot[mark=none,blue] {x^2};
\draw[myline] (2, \pgfkeysvalueof{/pgfplots/ymin}) -- (2, \pgfkeysvalueof{/pgfplots/ymax});
\draw[myline] (4, \pgfkeysvalueof{/pgfplots/ymin}) -- (4, \pgfkeysvalueof{/pgfplots/ymax});
\draw[myarrow] (2,5) -- node[above] {some text} (4,5);
\end{axis}
\end{tikzpicture}
\end{document}

Second edit:
I've created a pic with three args: initial x, final x and height of the arrow y (this last one could be substituted by a fixed value, if it is always the same, modifying the pic to use only two args).
\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{arrows.meta}
\tikzset{%
myline/.style = {green, very thick, dashed},
myarrow/.style = {blue, very thick, {Stealth}-{Stealth}},
pics/myint/.style n args={3}{code={%
\draw[myline] (#1, \pgfkeysvalueof{/pgfplots/ymin}) -- (#1, \pgfkeysvalueof{/pgfplots/ymax});
\draw[myline] (#2, \pgfkeysvalueof{/pgfplots/ymin}) -- (#2, \pgfkeysvalueof{/pgfplots/ymax});
\draw[myarrow] (#1,#3) -- node[above] {some text} (#2,#3);
}},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0,xmax=5
]
\addplot[mark=none,blue] {x^2};
\pic {myint={2}{4}{5}};
\end{axis}
\end{tikzpicture}
\end{document}
Of course, with \pic {myint={2}{4}{5}};, the output is the same as the previous one.