Environments create groups around their content, so any new
command/macro definition is local to this group and will be reset to its
original definition (which includes being undefined) after the end of
the environment. In general, you should avoid define macros inside
groups when you plan to use them globally. Define them in the preamble
instead.
You can however make the definition global, either by using
\gdef\macroname{..} instead of \newcommand{\macroname}{..} or by using
\global\let\macroname=\macroname after your \newcommand.
Note that \gdef doesn't has an optional argument to specify the number
of arguments, instead you need to list them in order, e.g. three
arguments is not [3] but #1#2#3 (after the macro name).
Best Regards,
Martin Scharrer