Referencing Why can't the end code of an environment contain an argument? you need to store #1
away for the “end” part. Usually this is done by an auxiliary macro:
\newenvironment*{verycontrivedexample}[1][]
{
\node [draw=black, #1] (Before) at (0, 1) {Before};
\def\optargument{#1}% Store optional argument for later use.
}
{
\node [draw=black, style/.expand once=\optargument] (After) at (0, 0) {After};
}
The style
key is used to expand \optargument
back to its content (otherwise you will most times end up with something like I do not know the key '/tikz/draw=red'
).
The same can be done with only styles, basically using the same approach:
\newenvironment*{verycontrivedexample}[1][]
{
\node [draw=black, #1] (Before) at (0, 1) {Before};
\tikzset{opt argument/.style={#1}}% Store optional argument for later use.
}
{
\node [draw=black, opt argument] (After) at (0, 0) {After};
}
In both cases, the macro \optargument
or the style opt argument
can be accessed by the user of the environment, both unintentionally or intentionally changing/overwriting the content (easy with the style, little bit harder with the macro).

\documentclass[tikz,convert]{standalone}% http://ctan.org/pkg/standalone
\newenvironment*{verycontrivedexample}[1][]
{
\node [draw=black, #1] (Before) at (0, 1) {Before};
\def\optargument{#1}% Store optional argument for later use.
}
{
\node [draw=black, style/.expand once=\optargument] (After) at (0, 0) {After};
}
\begin{document}
\begin{tikzpicture}
\begin{verycontrivedexample}[draw=red]
\end{verycontrivedexample}
\end{tikzpicture}
\end{document}